Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 192300

Re: Export CSV doesn't update the file when it runs via Task Scheduler

$
0
0

You are a charm... Just added add-pssnapin VMware.VimAutomation.Core after the Credential and started working..

 

Script after modification;

$username = 'Administrator'

$password = 'Password'

$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))

 

add-pssnapin VMware.VimAutomation.Core

 

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

 

==========================================================================================================

 

Where {$_.Name -like "*"} in here it will pick up all the hosts within the cluster. I have tried your script, but it didn't work. The issue sorted out now, by running the Task Schdeluer, the .csv file will be modified with new data and send it through email.

 

I highly appreciated your help LucD.

 

Thanks,

 

Message was edited by: Hussain Al Sayed


Viewing all articles
Browse latest Browse all 192300

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>