PoshCode Archive  Artifact [2dcadbd21e]

Artifact 2dcadbd21e84829d010780ca4ea8fa63a82f10e15d507a3415f8827a517c0e5d:

  • File Get-FormatData.ps1 — part of check-in [50ccefdf92] at 2018-06-10 14:10:15 on branch trunk — A wrapper around Get-FormatData that allows you to pipe types or objects into it. e.g. (user: Public Domain size: 2545)

# encoding: ascii
# api: powershell
# title: Get-FormatData
# description: A wrapper around Get-FormatData that allows you to pipe types or objects into it. e.g.
# version: 1.1
# type: function
# author: Public Domain
# license: CC0
# function: Get-FormatData
# x-poshcode-id: 6201
# x-archived: 2016-03-19T00:34:28
# x-published: 2016-02-04T22:10:00
#
# Get-Service | Get-FormatData
# [System.Management.Automation.AliasInfo] | Get-FormatData
#
function Get-FormatData {
	[CmdletBinding(HelpUri='http://go.microsoft.com/fwlink/?LinkID=144303', DefaultParameterSetName='S')]
	param(
		[Parameter(Position=0, ParameterSetName='S')]
		[ValidateNotNullOrEmpty()]
		[string[]]$TypeName = '*'
,
		[Parameter(ValueFromPipeline, ParameterSetName='I')]
		$InputObject
	)
	begin {
		if ($PSCmdlet.ParameterSetName -ceq 'I') {
			$seen = @{}
		} else {
			try {
				$outBuffer = $null
				if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) {
					$PSBoundParameters['OutBuffer'] = 1
				}
				$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Get-FormatData', [System.Management.Automation.CommandTypes]::Cmdlet)
				$scriptCmd = {& $wrappedCmd @PSBoundParameters}
				$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
				$steppablePipeline.Begin($PSCmdlet)
			} catch {
				throw
			}
		}
	}
	process {
		if ($PSCmdlet.ParameterSetName -ceq 'I') {
			if ($null -cne $InputObject) {
				$names = [System.Collections.Generic.List[string]]@()
				if ($InputObject -is [type]) {
					$t = $InputObject
					do {
						if (-not $seen.ContainsKey($t.FullName)) {
							$seen[$t.FullName] = 0
							$null = $names.Add([System.Management.Automation.WildcardPattern]::Escape($t.FullName))
						} 
						$t = $t.BaseType
					} while ($null -cne $t)
				} else {
					foreach ($n in $InputObject.pstypenames) {
						if (-not $seen.ContainsKey($n)) {
							$seen[$n] = 0
							$null = $names.Add([System.Management.Automation.WildcardPattern]::Escape($n))
						}
					}
				}
				if (0 -lt $names.Count) {
					Microsoft.PowerShell.Utility\Get-FormatData -TypeName $names.ToArray()
				}
			}
		} else {
			try {
				$steppablePipeline.Process($_)
			} catch {
				throw
			}
		}
	}
	end {
		if ($PSCmdlet.ParameterSetName -ceq 'S') {
			try {
				$steppablePipeline.End()
			} catch {
				throw
			}
		}
	}
}
<#
.ForwardHelpTargetName Get-FormatData
.ForwardHelpCategory Cmdlet
#>