cls
Remove-Variable -Name * -Force -ErrorAction SilentlyContinue
$VISRVS = 'visrv1','visrv2','visrv3'
foreach ($VISRV in $VISRVS)
{
$VIServer = Connect-VIServer $VISRV -ErrorAction SilentlyContinue
foreach ($VM in (Get-View -ViewType VirtualMachine ))
{
$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
$output = $Details.VM + ';' + $Details.Path
$output
$output | Out-File c:\misnamed.csv -Append
}
}
Disconnect-VIServer $VISRV -Confirm:$false
}
No comments:
Post a Comment