Fix error with variable in scriptblock

This commit is contained in:
maddieclayton 2017-11-27 16:12:37 -08:00
Родитель 3abc00f5a7
Коммит e4cd42063f
1 изменённых файлов: 10 добавлений и 6 удалений

Просмотреть файл

@ -16,13 +16,17 @@ if ($PSVersionTable.PSVersion.Major -ge 5)
$completerCommands = %COMPLETERCOMMANDS%
$completerCommands | ForEach-Object {
$completerObject = New-Object $_.AttributeType -ArgumentList $_.ArgumentList
Register-ArgumentCompleter -CommandName $_.Command -ParameterName $_.Parameter -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
$locations = $completerObject.GetCompleterValues()
$locations | Where-Object { $_ -Like "$wordToComplete*" } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }
$type = $_.AttributeType
$args = "@()"
if ($_.ArgumentList.Count -ne 0) {
$temp = $_.ArgumentList -join "`", `""
$args = "@(`"" + $temp + "`")"
}
$sb = [scriptblock]::Create("param(`$commandName, `$parameterName, `$wordToComplete, `$commandAst, `$fakeBoundParameter) `
`$completerObject = New-Object $type -ArgumentList $args `
`$arguments = `$completerObject.GetCompleterValues() `
`$arguments | Where-Object { `$_ -Like `"`$wordToComplete*`" } | ForEach-Object { [System.Management.Automation.CompletionResult]::new(`$_, `$_, 'ParameterValue', `$_) }")
Register-ArgumentCompleter -CommandName $_.Command -ParameterName $_.Parameter -ScriptBlock $sb
}
}