Created
April 20, 2018 06:48
-
-
Save OCram85/6579153ba5bc36505cb70ccd286fbb71 to your computer and use it in GitHub Desktop.
PowerShell Advanced Function: Parameter binding by TypeName
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 Get-MyAwesomeCustomType { | |
[CmdletBinding()] | |
[OutputType('ModuleName.Context.Identifier')] | |
param() | |
$returnObj = [PSCustomObject]@{ | |
somePropertyKey = 'awesome value' | |
foo = 'bar' | |
} | |
$returnObj.PsObject.TypeNames.Insert(0, 'ModuleName.Context.Identifier') | |
Write-Output $returnObj | |
} |
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 Invoke-AwesomeStuff { | |
param( | |
[Parameter(Mandatory = $true)] | |
[ValidateNotNullOrEmpty()] | |
[PSTypeName('ModuleName.Context.Identifier')]$InputObj | |
) | |
Write-Host $InputObj.foo | |
} |
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
. .\Get-MyAwesomeCustomType.ps1 | |
. .\Invoke-AwesomeStuff.ps1 | |
$foo = Get-MyAwesomeCustomType | |
Invoke-AwesomeStuff -InputObj $foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment