41 How to get list of “Running” Virtual machine in the SCVMM site?
In the below PowerShell script:-
- Name and save the script as “Get-VMList.PS1”.
- Create a temp folder into Drive C.
- The output CSV file will be saved to the temp folder and show total running VMs count on the PowerShell screen.
In case of any hurdle, please Contact Us
$VMs = Get-SCVirtualMachine | where { $_.HostGroupPath -like "*PRD*"}
$VMs | Select Name,HostName,@{Name='Memory(GB)';Expression={$_.Memory/1024}},CPUcount,StatusString | Sort-Object -Property HostName | Export-Csv C:\temp\PRD-HyperV-Cluster-Report_$(get-date -f "yyyy-MM-dd_HH-mm-ss").csv
$VM_count = ($VMs | where { $_.VirtualMachineState -eq "Running"}).count
write-host "PRD has total $VM_count running VMs @ $(get-date -f "yyyy-MM-dd_HH:mm:ss")"