Find VM name and Folder is mismatch

Long time no see you guys! happy to come back and share with you my IT knowledge!.
Today I would like to share with you a very necessary Powercli script that may be useful on any VMware environment.

As most of us know, when we\re “renaming” VM’s name for any such a reason, and not preforming “Storage vMotion” the old name of that VM still appears in the datastore, it defiantly can make some troubles when you try to identity VM name.

You can run the following script and you will be able to identify all VM’s that renamed ever and have not been migrated to different DS.

$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
About Meir Peleg 337 Articles
My name is Meir Peleg, (Born 30/04/1991) live in ISRAEL. Live and breath IT world. Microsoft MVP Windows IT & VMware vExpert.