Created
February 18, 2017 17:28
-
-
Save simonjgreen/7cc99efea03562c4529585044c2c5457 to your computer and use it in GitHub Desktop.
Look up folder path for object in PowerCLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filter Get-FolderPath { | |
$_ | Get-View | % { | |
$row = "" | select Name, Path | |
$row.Name = $_.Name | |
$current = Get-View $_.Parent | |
# $path = $_.Name # Uncomment out this line if you do want the VM Name to appear at the end of the path | |
$path = "" | |
do { | |
$parent = $current | |
if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path} | |
$current = Get-View $current.Parent | |
} while ($current.Parent -ne $null) | |
$row.Path = $path | |
$row | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment