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
}
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
in that list, i am trying to include
1. the vms not registered
2. the vms network disconnction
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.
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