Forum Discussion
amontaser_egid
Feb 18, 2023Copper Contributor
Getting all virtual machines in a Hyper-V cluster using Python and WinRM
Hello, I am trying to use Python and WinRM to retrieve a list of all virtual machines in a Hyper-V cluster. I have a PowerShell script that works to retrieve the virtual machines owned by the curren...
AndySvints
Feb 23, 2023Iron Contributor
Hello amontaser_egid,
Try something like this:
ps_script = """
$vm_list = Get-ClusterGroup -Cluster $env:computername | Where-Object {$_.GroupType -eq 'VirtualMachine'} | Get-VM
$vm_names = $vm_list.Name
Write-Output $vm_names
"""
Hope that helps.
- amontaser_egidMar 07, 2023Copper Contributor
Hello AndySvints, thanks for your help. I try the code but unfortunately, it still retrieves one node VMs, but when I run the script on the hyper-v machine it gets the whole list,