Skip to content

Instantly share code, notes, and snippets.

@simonjgreen
Created February 18, 2017 17:28
Show Gist options
  • Save simonjgreen/7cc99efea03562c4529585044c2c5457 to your computer and use it in GitHub Desktop.
Save simonjgreen/7cc99efea03562c4529585044c2c5457 to your computer and use it in GitHub Desktop.
Look up folder path for object in PowerCLI
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