Private/Get-PropertyOrder.ps1
#function to extract properties function Get-PropertyOrder { <# .SYNOPSIS Gets property order for specified object. .DESCRIPTION Gets property order for specified object. .INPUTS System.Management.Automation.PSCustomObject[] .INPUTS System.Management.Automation.PSCustomObject .NOTES - Troy Lindsay - Twitter: @troylindsay42 - GitHub: tlindsay42 .EXAMPLE .LINK https://tlindsay42.github.io/PSRyver/Private/Get-PropertyOrder/ .LINK https://github.com/tlindsay42/PSRyver/blob/master/PSRyver/Private/Get-PropertyOrder.ps1 .FUNCTIONALITY PowerShell Language #> [CmdletBinding( HelpUri = 'https://tlindsay42.github.io/PSRyver/Private/Get-PropertyOrder/' )] [OutputType( [String[]] )] [OutputType( [String] )] param ( # Specifies the objects to convert to an array of property value pairs. [Parameter( Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromRemainingArguments = $false )] [PSCustomObject[]] $InputObject, # Specifies member types to include. [Parameter( Position = 1 )] [ValidateSet( 'AliasProperty', 'CodeProperty', 'Property', 'NoteProperty', 'ScriptProperty', 'Properties', 'PropertySet', 'Method', 'CodeMethod', 'ScriptMethod', 'Methods', 'ParameterizedProperty', 'MemberSet', 'Event', 'Dynamic', 'All' )] [String[]] $MemberType = @( 'NoteProperty', 'Property', 'ScriptProperty' ), # Specifies properties to exclude. [Parameter( Position = 2 )] [ValidateNotNullOrEmpty()] [String[]] $ExcludeProperty ) begin { $function = $MyInvocation.MyCommand.Name Write-Verbose -Message ( "Beginning: '${function}' with ParameterSetName '$( $PSCmdlet.ParameterSetName )' and Parameters: " + ( $PSBoundParameters | Remove-SensitiveData | Format-Table -AutoSize | Out-String ) ) } process { # Get properties that meet specified parameters ( $InputObject | Select-Object -First 1 ).PSObject.Properties | Where-Object -FilterScript { $MemberType -contains $_.MemberType } | Select-Object -ExpandProperty 'Name' | Where-Object -FilterScript { -not $ExcludeProperty -or $ExcludeProperty -notcontains $_ } } end { Write-Verbose -Message "Ending: '${function}'." } } |