List ALL properties and subproperties of a variable in Powershell

With one small adjustment, the script in my previous post can be used as a function to list all properties and subproperties of any variable in Windows Powershell. It’s a great way to explore Powershell and create scripts. I used to do the following procedure very often:

$a = Get-Process #For Example
$a
$a[0] | fl *
$a[0].Modules | fl *
etc.

With this function loaded into my profile, this becomes:

$a = Get-Process # For Example
Get-ALLPropertyNames ‘$a’

Here’s the function:

Function Get-ALLPropertyNames
{

param([string]$VariableName)

# Function that lists the properties
function Show-Properties
{
Param($BaseName)
If ((Invoke-Expression $BaseName) -ne $null)
{
$Children = (Invoke-Expression $BaseName) | Get-Member -MemberType Property
ForEach ($Child in ($Children | Where {$_.Name -ne “Length” -and $_.Name -notmatch “Dynamic[Property|Type]” -and $_.Name -ne “”}))
{
$NextBase = (“{0}.{1}” -f $BaseName, $Child.Name)
$Invocation = (Invoke-Expression $NextBase)
If ($Invocation)
{
If ($Invocation.GetType().BaseType.Name -eq “Array”)
{
# Recurse through subdir
$NextBase = $NextBase + ‘[0]’
Show-Properties $NextBase
}
ElseIf ($Child.Definition -notlike “System*”)
{
# Recurse through subdir
Show-Properties $NextBase
}
Else
{
$myObj = “” | Select Name, Value
$myObj.Name = $NextBase
$myObj.Value = $Invocation
$myObj
}
}
Clear-Variable Invocation -ErrorAction SilentlyContinue
Clear-Variable NextBase -ErrorAction SilentlyContinue
}
}
Else
{
Write-Warning “Expand Failed for $BaseName”
}
}

# Actual start of script
If ((Invoke-Expression $VariableName).GetType().BaseType.Name -eq “Array”)
{
$VariableName = $VariableName + ‘[0]’
}
Show-Properties $VariableName
}

Twitter is available in more than 40 languages around the world.. I went on nursing elsewhere, where I saw other patients suffering all kinds of abuse. This will add all of the available HD channels for all packages.. Why don’t they make all that stuff unnecessary roughness, instead of helmet to helmet, defenseless receiver That defenseless receiver is the worst rule I ever saw. McCARTHY: Well, I mean, what was so different about it was you really had sports going NFL Jerseys China into prime time for the first time. We look forward to watching him in Rio and wish him continued success.”New Niners coach Chip Kelly had been excited to work with Hayne in 2016.”The support and understanding from the 49ers organization was unbelievable when I let them know about my decision to pursue another dream,” said Hayne, who thanked Baalke, Kelly, former head coach Jim Tomsula and his teammates, especially his “running back brothers.”. See the most Fake ray bans read stories in Entertainment this hour think we have done an exceptional job [on diversity], and of Angels shows our commitment, Moonves declared in a 2000 interview. Next month, we will premiere our new fall schedule on the CBS Television Network. You not going to Wholesale NFL Jerseys be talking about the football team, talking about our team, talking about my coaches, expecting to get things from this football team. He must also be able to work will all levels of management and have superior training and delegation abilities. That point was drawn cheap fake oakleys in terrifyingly stark terms during the Cuban Missile Crisis of 1962, whenCastro allowed the Soviets to base on his soil missiles that could carry nuclear warheads to Washington or New York in minutes. As great as Mason Plumlee eventually became, Okafor could represent Duke’s first true post scorer since Sheldon Williams. MLB Extra Innings too. The NFL placed Hardy on paid suspension during the appeal, and he missed all but one game of the 2014 season, his last as a member of the Carolina Panthers. In a moment, I’ll hand the call over to Mike, Bruce and Pat for some introductory remarks. The FDA reports these possible risks: visual disturbances, such as glare, halos and/or double Cheap Replica ray bans outlet vision; poor nighttime vision, and the development of severe dry eye syndrome (the patient cannot produce enough tears to keep the eye moist). Catch is excellent. Would they come out at the end when already established? That would lead to questions of when the first athlete would be going in openly homosexual with the knowledge on the table. Twitter’s Olympic results speak to Fake Oakleys its minimal effort. wholesale jerseys Nike air max ray ban sunglasses oakley sunglasses cheap michael kors outlet online This chanel sunglasses nike roshe run ralph lauren outlet online coach factory store is new balance louboutin shoes rolex watches for sale beats by dr dre as designer bags michael kors handbags clearance lululemon canada nike store opposed louis vuitton outlet online nike air max michael kors outlet bebe dresses to uggs outlet louis vuitton outlet online hermes birkin nike free run 5.0 the chanel ralph lauren uk louis vuitton outlet online harrods london idea giuseppe zanotti air force supra shoes oakley canada of burberry nike roshe baseball jerseys hilfiger outlet simply vans prada outlet converse outlet louis vuitton eating oakley oakley sunglasses cheap northface swarovski and barbour mens jackets kate spade outlet glasses online basketball shoes sleeping longchamp outlet ray ban sunglasses prada shoes coach outlet store in puma jordans nike store ralph lauren uk a hermes belt ugg boots p90x workout schedule north face jackets particular jordans for sale toms shoes outlet cheap barbour jackets polo ralph geographical nike free thomas sabo uk burberry nfl jerseys spot.

6 thoughts on “List ALL properties and subproperties of a variable in Powershell”

  1. Hey Hugo. This is just what I was looking for. I can’t get this function to work, though and I was wondering if you could help.

    I pasted the contents of the function script into a PS1 file and ran it (ie .\Get-AllPropertyNames.ps1). Then, I ran the following sequence once the function was loaded:

    $a = Get-Process
    Get-AllPropertyNames $a

    I attempted variations on the function call: ie. Get-AllPropertyNames ‘$a’

    I suspect I’m missing something that’s right in front of me. Any thoughts on this?

    BTW, I really dig your blog. You put some fantastic content.

    Cheers.

    1. Matt,
      It does work when running from a .ps1 file, but you’ll have to dot-source it (e.g.: . .\script.ps1) to keep the function “alive” in your session.
      Thank you very much for dropping a comment.
      Hugo

Leave a Reply