4 Replies Latest reply on Jun 4, 2019 3:20 AM by LucD

    Get Orphan vms Across all vcenter

    piyushranusri Novice

      looking for a powershell script, by i can get (only view) orphan vms details across all 23 vcenter in environment. If any one have please share.

      couple of got while searching but have to do for all 23 vcenter so is this correct which i updated below?

       

      get-view -ViewType VirtualMachine -Filter @{'RunTime.ConnectionState'='orphaned'}

       

      Get-NetworkAdapter (get-vm | where {$_.powerstate -eq “poweredon”}) | Where { $_.connectionstate.connected -eq “$F” } | select parent, connectionstate

      or

      Get-NetworkAdapter (get-vm | where {$_.powerstate -eq “poweredon”}) | Where { $_.connectionstate.connected -eq “$null” } | select parent, connectionstate

       

      ============================

      Import-Module VMware.VimAutomation.Vds

      $vcenterip = @("")

       

      foreach ($vcenter in $vcenterip){

      Write-Output 'Before connecting'

      Connect-VIServer -Server "$vcenter"

      Write-Output "Connected to $vcenter"

       

      Get-NetworkAdapter (get-vm | where {$_.powerstate -eq “poweredon”}) | Where { $_.connectionstate.connected -eq “$null” } | select parent, connectionstate

      disconnect-viserver -confirm:$false |  ConvertTo-Html | Out-File c:\temp\$vcenter.html

      }