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

Mar 16, 2011 at 9:42 PM

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).


Mar 19, 2011 at 12:50 AM

I don't think these are the only characters which can be put in a display name but vause a WQL query to break.  I want to try to get a complete list before putting  a fix in. I'm going to make this a work item so it doesn't slip of my to do list.


Mar 19, 2011 at 12:50 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.