Hello,
I faced with the following problem some days ago: unable to get VM view by executing "get-view" cmdlet with filter containig "Name" property. This issue occurs only with VMs that managed by vCloud Director.
Everyone knows that vCD gives the name to VMs in vCenter like this: "VMName (<vCD_ID>)" - where <vCD_ID> is an identifier that can be expressed as this regex:"(\w|\d){8}[-]+((\w|\d){4}[-]+){3}(\w|\d){12}".
I tried to execute something like this: "Get-View -ViewType VirtualMachine -Filter @{"Name" = "<VMName> (<vCD_ID>)"}"
And like this: "Get-View -ViewType VirtualMachine -Filter @{"Name" = "^$($<VMName> (<vCD_ID>))$"}"
Cmdlet returns an empty response.
To my surprise if i try to execute: "Get-View -ViewType VirtualMachine -Filter @{"Name" = "<VMName>"}" - it responed VM view.
The problem is that <VMName> without identifier is not a unique name of vCD VM. So powercli can respond an array of VMS View objects.
Anyone else seeing similar issue?
Just to make sure, you did it like this ?
$VMName = "<VM Name>"
$vCDID = "<vCD ID>"
Get-View -ViewType VirtualMachine -Filter @{"Name" = "^$($VMName)$($vCDID)$"}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The value of the Get-View -Filter parameter is a regular expression. In a regular expression, the opening parenthesis (, and the closing parenthesis ) have special meanings. So you have to escape them using the backslash character \. The following command will work:
Get-View -ViewType VirtualMachine -Filter @{"Name" = "<VMName> \(<vCD_ID>\)"}
RvdNieuwendijkRvdNieuwendijk,
Thanks a lot! This form work correct.
I think you can also use this:
[uri]::EscapeDataString($VMName)