Use the following PowerCLI script to power on a list of Virtual Machines from a CSV file.
import-module vmware.vimautomation.core
$vcenter = <my vCenter server>
connect-viserver $vcenter
$allvms = import-csv RVTools_tabvInfo.csv
foreach ($strNewVMName in $allvms)
{
#gets all the VM's properties. We're interested in the PowerState Property.
$vmdata = Get-view -ViewType VirtualMachine -Filter @{"name" = $strNewVMName.vm} #vm is the column header name in the csv on the first line.
#if the PowerState is not PoweredOn, then power it on.
if ($vmdata.Runtime.PowerState -ne "PoweredOn")
{
Write-Host "Powering on "$strNewVMName.vm
Start-VM -VM $strNewVMName.vm
Sleep 2
}
}
No comments:
Post a Comment
Thank you for your comment.