This project is read-only.

Get-VM - Ability to Handle "[" and "]" Characters?


While Executing: Get-VM
If one of the VM names in the -VM parameter contains the characters "[" or "]" the nested command (in the VM.ps1 script) ...
Get-WmiObject -computername $Server -NameSpace $HyperVNamespace -Query $WQL | Add-Member -MemberType ALIASPROPERTY -Name "VMElementName" -Value "ElementName" -PassThru
...returns a NULL value.
As a quick fix, I just added the following (right after the existing $Name = $Name.Replace("*","%")
line 58):
        $Name = $Name.Replace("[","%")
        $Name = $Name.Replace("]","%")
I didn't want to have to ask the end user to change the name of their VMs, so I thought this would be the best way to handle this "issue" (I am not even sure it is an issue).


Kansaswind wrote Oct 2, 2014 at 6:27 PM

I'm not sure I would want to replace brackets with a wildcard. I've ran into the same problem and I would prefer brackets to be replaced with parentheses.
 $Name = $Name.Replace("[","(")
 $Name = $Name.Replace("]",")")