Hello,
Long time haven't posted in VMWare forum.. I have a script which generates the hosts UpTime and export the result to CSV file. Then it sends the CSV file as attachment to our helpdesk system. When I run the script manually through PowerCLI ./Get-HostUpTime.ps1 it runs fine and it sends the updated file, however, when the script runs through the Windows Task Scheduler, it runs fine but it doesn't update the CSV file and it always sends the old one.
$username = 'Administrator'
$password = 'password'
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
Connect-VIServer -Server vCenter01 -Credential $cred
Get-View -ViewType "HostSystem" -property Name, Summary | `
where {
$_.name -like "*" } |`
select Name, @{N="Uptime"; E={(Get-Date) - $_.Summary.Runtime.BootTime}
} |sort Name | Export-csv C:\Scripts\HostsUpTime.csv
Disconnect-VIServer -confirm:$false
Send-MailMessage -From vSphere@Domain.com -To helpdesk@Domain.com -Subject "vSphere Hosts UpTime" -SmtpServer SMTPHUB001 -Attachments C:\Scripts\HostsUpTime.csv
Any help?
Thanks,