Skip to content

Instantly share code, notes, and snippets.

@Graham-Beer
Last active September 4, 2018 13:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Graham-Beer/693ded0ae3033b95e011a922b87cce58 to your computer and use it in GitHub Desktop.
Save Graham-Beer/693ded0ae3033b95e011a922b87cce58 to your computer and use it in GitHub Desktop.
Alternative to Get-Member with a cleaner output to host
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