Skip to content

Instantly share code, notes, and snippets.

@jeffgreenca
Created November 5, 2015 23:15
Show Gist options
  • Save jeffgreenca/c1c84d9577ad301ee017 to your computer and use it in GitHub Desktop.
Save jeffgreenca/c1c84d9577ad301ee017 to your computer and use it in GitHub Desktop.
Recursive variable dump, appropriate for crawling VMware PowerCLI Get-View objects
function vd($v, $p) {
if($v -eq $null) {
echo "[$p] -> null"
} else {
$v | gm -MemberType Property | % {
if ($_.Definition.ToString() -match "\[\]") {
for($i = 0; $i -lt $v.$($_.name).length; $i++) {
vd $v.$($_.name)[$i] "$p.$($_.name)[$i]"
}
} elseif ($_.Definition -cmatch "(^System)|(^[a-z])") {
echo "[$p.$($_.name)] -> $($v.$($_.name))"
} else {
vd $v.$($_.name) ($p + "." + $_.name)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment