Skip to content

Instantly share code, notes, and snippets.

@exactmike
Created April 27, 2018 15:11
Show Gist options
  • Select an option

  • Save exactmike/3051a812984417c3f77c6de08406b359 to your computer and use it in GitHub Desktop.

Select an option

Save exactmike/3051a812984417c3f77c6de08406b359 to your computer and use it in GitHub Desktop.
Register-ArgumentCompleter Examples
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