Skip to content

Commit 11e7988

Browse files
authored
Merge pull request Azure#5034 from maddieclayton/FixPsm1
Fix error with variable in scriptblock
2 parents 5012cf4 + 32a8aa3 commit 11e7988

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tools/AzureRM.Example.psm1

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ if ($PSVersionTable.PSVersion.Major -ge 5)
1616
$completerCommands = %COMPLETERCOMMANDS%
1717

1818
$completerCommands | ForEach-Object {
19-
$completerObject = New-Object $_.AttributeType -ArgumentList $_.ArgumentList
20-
Register-ArgumentCompleter -CommandName $_.Command -ParameterName $_.Parameter -ScriptBlock {
21-
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
22-
23-
$locations = $completerObject.GetCompleterValues()
24-
$locations | Where-Object { $_ -Like "$wordToComplete*" } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }
19+
$type = $_.AttributeType
20+
$args = "@()"
21+
if ($_.ArgumentList.Count -ne 0) {
22+
$temp = $_.ArgumentList -join "`", `""
23+
$args = "@(`"" + $temp + "`")"
2524
}
25+
$sb = [scriptblock]::Create("param(`$commandName, `$parameterName, `$wordToComplete, `$commandAst, `$fakeBoundParameter) `
26+
`$completerObject = New-Object $type -ArgumentList $args `
27+
`$arguments = `$completerObject.GetCompleterValues() `
28+
`$arguments | Where-Object { `$_ -Like `"`$wordToComplete*`" } | ForEach-Object { [System.Management.Automation.CompletionResult]::new(`$_, `$_, 'ParameterValue', `$_) }")
29+
Register-ArgumentCompleter -CommandName $_.Command -ParameterName $_.Parameter -ScriptBlock $sb
2630
}
2731
}
2832

0 commit comments

Comments
 (0)