4 Replies Latest reply on May 15, 2019 7:21 AM by LucD

    Virtual machines status.

    vmk2014 Hot Shot

      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

        • 1. Re: Virtual machines status.
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          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

          }

          • 2. Re: Virtual machines status.
            vmk2014 Hot Shot

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

             

            Thanks

            vmk

            • 3. Re: Virtual machines status.
              vmk2014 Hot Shot

              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

              • 4. Re: Virtual machines status.
                LucD Guru
                vExpertCommunity WarriorsUser Moderators

                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

                }

                1 person found this helpful