VMware Cloud Community
vmk2014
Expert
Expert
Jump to solution

Virtual machines status.

Hi All,

I have a list of around 600 VM's but not sure whether these VM's still exist or running in Vcenter or migrated to the Cloud. Can we confirm from power cli whether the VM's from list C:\temp\vmlist  exist or running on the vc? Example VC name - vc01.

thanks

vmk

Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If the VMs running in the cloud are not found from with your connection to the vCenter(s), you could do

Get-Content -Path C:\temp\vmlist |

ForEach-Object -Process {

   $obj = [ordered]@{

    VM = $_

   }

   $vm = Get-VM -Name $_ -ErrorAction SilentlyContinue

   if ($vm)

   {

    $obj.Add('VC', ([uri]$vm.ExtensionData.Client.ServiceUrl).Host)

   }

   else

   {

    $obj.Add('VC', 'VM not found')

   }

   New-Object PSObject -Property $obj

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

If the VMs running in the cloud are not found from with your connection to the vCenter(s), you could do

Get-Content -Path C:\temp\vmlist |

ForEach-Object -Process {

   $obj = [ordered]@{

    VM = $_

   }

   $vm = Get-VM -Name $_ -ErrorAction SilentlyContinue

   if ($vm)

   {

    $obj.Add('VC', ([uri]$vm.ExtensionData.Client.ServiceUrl).Host)

   }

   else

   {

    $obj.Add('VC', 'VM not found')

   }

   New-Object PSObject -Property $obj

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Thanks, LucD. It saved manual effort for validating each vm from vc.

Thanks

vmk

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

Can we validate those VM's which we are able to find running on which ESXi version? I mean  VM's running on VC.

thanks

vmk

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, try like this

Get-Content -Path C:\temp\vmlist |

ForEach-Object -Process {

   $obj = [ordered]@{

     VM = $_

   }

   $vm = Get-VM -Name $_ -ErrorAction SilentlyContinue

   if ($vm)

   {

     $obj.Add('VC', ([uri]$vm.ExtensionData.Client.ServiceUrl).Host)

     $obj.Add('ESXVersion', "$($vm.VMHost.Version) $($vm.VMHost.Build)")

   }

   else

   {

     $obj.Add('VC', 'VM not found')

     $obj.Add('ESXVersion', 'na')

   }

   New-Object PSObject -Property $obj

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference