You guys have help me before with my shutdown script which I have got from you guys anyway, I am looking to better it.
So this is what I would like to do but I can't becasue I don't know how to. I took this script from an upgrade vmware tools and instead would like to use some of its context to ShutDown VM's from a list.txt file, check to make sure they are down create a log file that they are down then once they are all down send an email.
I know I have to add probably a Sleep to wait for each one in here as well.
I really appreciate your help.
1. Get the VM's from a text file -
$colVMs = Get-Content "C:\list.txt" | % { Get-VM $_ | Shutdown-VMGuest -Confirm:$false }
2. Start the Shutdown process -
3. Create a log file -
$logFile = New-Item -ItemType File -Path "C:\Powershell\temp\power\VMware-PowerOff_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).log"
4. Get the information on each machine PowerState -
foreach ($VM in $colVMs) {
$VMPower = $VM.PowerState
$VMName = $VM.name
$OS = (Get-VMGuest $VM)
$vmID = get-vm $VM | foreach {get-view $_.Id}
5. Check that the VMs are off -
if ($VMPower -notmatch "PoweredON") {
Write-Host $VMName `t "Powered OFF" -ForegroundColor Red
Add-Content -Path $logFile -Value ($VMName + "`t`tShutDown`t`tPowered OFF")
}
6. Send out an email with a log letting me know that they have ShutDown
send-mailmessage -SmtpServer "smtp.com" `
-from "VM-ShutDown Thank you,
Express