1313// ----------------------------------------------------------------------------------
1414
1515using System ;
16+ using System . Collections . Generic ;
1617using System . Management . Automation ;
1718
1819namespace Microsoft . Azure . Commands . ResourceManager . Common . ArgumentCompleters
@@ -25,10 +26,22 @@ public PSArgumentCompleterAttribute(params string[] argumentList) : base(CreateS
2526
2627 public static ScriptBlock CreateScriptBlock ( string [ ] resourceTypes )
2728 {
28- string scriptResourceTypeList = "'" + String . Join ( "' , '" , resourceTypes ) + "'" ;
29+ List < string > outputResourceTypes = new List < string > ( ) ;
30+ foreach ( string resourceType in resourceTypes )
31+ {
32+ if ( resourceType . Contains ( " " ) )
33+ {
34+ outputResourceTypes . Add ( "\' \' " + resourceType + "\' \' " ) ;
35+ }
36+ else
37+ {
38+ outputResourceTypes . Add ( resourceType ) ;
39+ }
40+ }
41+ string scriptResourceTypeList = "'" + String . Join ( "' , '" , outputResourceTypes ) + "'" ;
2942 string script = "param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)\n " +
3043 String . Format ( "$values = {0}\n " , scriptResourceTypeList ) +
31- "$values | Where-Object { $_ -Like \" $wordToComplete*\" } | Sort-Object | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }" ;
44+ "$values | Where-Object { $_ -Like \" $wordToComplete*\" -or $_ -Like \" '$wordToComplete* \" } | Sort-Object | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }" ;
3245 ScriptBlock scriptBlock = ScriptBlock . Create ( script ) ;
3346 return scriptBlock ;
3447 }
0 commit comments