VM folder name mismatch query using PowerShell
Hats off to Luc at www.virtu-al.net for this incredibly useful PowerShell script to identify the display names of VMs and any that don’t match their folder structure. If you’ve ever unregistered a virtual machine in vCenter and sort of spaced where it lived on your datastores, trying to find a VM’s hostname in a bunch of folders that don’t match that display name can be an utter pain. Oftentimes, I’ve had to do this under pressure. Like during an outage. Fun.
Connect-VIServer vcenterhost
$VMFolder = @()
Foreach ($VM in (Get-VM |Get-View)){
$Details = "" |Select-Object VM,Path
$Folder = ((($VM.Summary.Config.VmPathName).Split(']')[1]).Split('/'))[0].TrimStart(' ')
$Path = ($VM.Summary.Config.VmPathName).Split('/')[0]
If ($VM.Name-ne $Folder){
$Details.VM= $VM.Name
$Details.Path= $Path
$VMFolder += $Details
}
}
$VMFolder |Export-Csv -NoTypeInformation C:Mismatch.csv
Simply replace vcenterhost with your vCenter’s name and go for it.
Categorised as: Virtualization