Last active
September 4, 2018 13:10
-
-
Save Graham-Beer/693ded0ae3033b95e011a922b87cce58 to your computer and use it in GitHub Desktop.
Alternative to Get-Member with a cleaner output to host
This file contains 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
function Format-Member { | |
[CmdletBinding()] | |
[alias("fm")] | |
param ( | |
[parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] | |
[System.Management.Automation.PSObject] | |
$InputObject | |
) | |
process { | |
$Members = Get-Member -InputObject $InputObject | |
'{0}: {1}' -f "TypeName", $Members.TypeName[0] | |
$Members | ForEach-Object { | |
$CurrentObject = $_ ; | |
[PSCustomObject]@{ | |
Name = $CurrentObject.Name | |
MemberType = $CurrentObject.MemberType | |
Type = ($CurrentObject.Where({$_.MemberType -ne 'AliasProperty'}).Definition -split '\s')[0] | |
Getter = $CurrentObject.Where({$_.MemberType -eq 'Property' -and $_.Definition -match 'get'}) -as [bool] | |
Setter = $CurrentObject.Where({$_.MemberType -eq 'Property' -and $_.Definition -match 'set'}) -as [bool] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment