VMware Cloud Community
piyushranusri
Enthusiast
Enthusiast

Get Orphan vms Across all vcenter

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

}

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

You can have a look at my VMX Raiders Revisited to find orphaned VMs.

But looking at the code you included, I'm not sure what exactly you are looking for.
The general consensus on orphaned VMs is that they are VMs that still live on storage, but aren't registered to any vCenter anymore.
Perhaps you can explain a bit more what you consider orphaned VMs.


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

Reply
0 Kudos
piyushranusri
Enthusiast
Enthusiast

in that list, i am trying to include

1. the vms not registered

2. the vms network disconnction

Reply
0 Kudos
piyushranusri
Enthusiast
Enthusiast

I see VMX Raiders Revisited - LucD notes and here you are referring that it will delete ask well ?

what if i just want to view and save the output.

Reply
0 Kudos
LucD
Leadership
Leadership

No, it will not delete the orphaned VMs, but it will try to register them.
You can comment out the registration part.

If you also use the WhatIf switch you will only get the results, no registration will happen.

Not sure how you want to get the network connection on unregistered VMs?


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

Reply
0 Kudos