I want to sort vm's based on the folder they are in anyone know how to do that? Even better export it to excel sheet.
You want to folder name only or the complete folder path ?
If it's only the folder name you can use a slight variation on the script in .
Something like this
$report = @() Get-Folder | %{ $folder = $_.Name $_ | Get-VM | %{ $row = "" | select FolderName, VMName $row.FolderName = $folder $row.VMName = $_.Name $report += $row } } $report | Sort-Object -Property FolderName | Export-Csv "C:\VM-by-folder.csv" -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You want to folder name only or the complete folder path ?
If it's only the folder name you can use a slight variation on the script in .
Something like this
$report = @() Get-Folder | %{ $folder = $_.Name $_ | Get-VM | %{ $row = "" | select FolderName, VMName $row.FolderName = $folder $row.VMName = $_.Name $report += $row } } $report | Sort-Object -Property FolderName | Export-Csv "C:\VM-by-folder.csv" -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference