Here is a script to check Power state of a VM using power shell.
Create the .csv file (vmlist.csv) with header name as "name" and list all the VMs under it, for which power state needs to be determined. Enter the appropriate vCenter name to connect to the vCenter. The list of VMs and its power state will be displayed on the screen.
Add-PSSnapin VMware.VimAutomation.Core (For vSphere 5.5 or below)
Import-Module VMware.VimAutomation.Core (For vSphere 6.0 and above)
Connect-VIServer vCenterName
$vms = Import-csv "C:\temp\vmlist.csv"
foreach ($vm in $vms)
{
$p = get-vm $vm.name | Select-Object Powerstate
$q = ($p).powerstate
Write-output "$($vm.name) `t $($q)"
}
Create the .csv file (vmlist.csv) with header name as "name" and list all the VMs under it, for which power state needs to be determined. Enter the appropriate vCenter name to connect to the vCenter. The list of VMs and its power state will be displayed on the screen.
Add-PSSnapin VMware.VimAutomation.Core (For vSphere 5.5 or below)
Import-Module VMware.VimAutomation.Core (For vSphere 6.0 and above)
Connect-VIServer vCenterName
$vms = Import-csv "C:\temp\vmlist.csv"
foreach ($vm in $vms)
{
$p = get-vm $vm.name | Select-Object Powerstate
$q = ($p).powerstate
Write-output "$($vm.name) `t $($q)"
}
Comments
Post a Comment