Created
April 27, 2018 15:11
-
-
Save exactmike/3051a812984417c3f77c6de08406b359 to your computer and use it in GitHub Desktop.
Register-ArgumentCompleter Examples
This file contains hidden or 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
| Register-ArgumentCompleter -CommandName @( | |
| 'Set-OneShellUserProfileSystem' | |
| 'Get-OneShellUserProfileSystem' | |
| ) -ParameterName 'Identity' -ScriptBlock { | |
| param($commandName, $parameterName, $WordToComplete, $commandAst, $fakeBoundParameter) | |
| $OrgProfilePath = if ($null -eq $fakeBoundParameter.OrgProfilePath) {$script:OneShellOrgProfilePath} else {$fakeBoundParameter.OrgProfilePath} | |
| $Path = if ($null -eq $fakeBoundParameter.Path) {$Script:OneShellUserProfilePath} else {$fakeBoundParameter.Path} | |
| $GetOneShellUserProfileSystemParams = @{ | |
| Path = $Path | |
| OrgProfilePath = $OrgProfilePath | |
| } | |
| if (Test-IsNotNullOrWhiteSpace -String $fakeBoundParameter.ProfileIdentity) | |
| { | |
| $GetOneShellUserProfileSystemParams.ProfileIdentity = $fakeBoundParameter.ProfileIdentity | |
| } | |
| $PotentialSystemIdentities = @( | |
| $Systems = Get-OneShellUserProfileSystem @GetOneShellUserProfileSystemParams | |
| $Systems.Name | |
| $Systems.Identity | |
| ) | |
| $PotentialSystemIdentities = @($PotentialSystemIdentities | Where-Object -FilterScript {$_ -like "$WordToComplete*"}) | |
| foreach ($psi in $PotentialSystemIdentities) | |
| { | |
| [System.Management.Automation.CompletionResult]::new($psi, $psi, 'ParameterValue', $psi) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment