Question

I ran into a problem where some variables, that I'm comparing against using the like operator, contain square brackets and parenthesis.

I am using the VMware PowerCLI plugin (which should be irrelevant) and my expression is as follows -

Get-VM | Where { (Get-CDDrive $_).ISOPath -like "*$ISOLocation*" }

It is failing to identify the similarity between strings when the value of $ISOLocation is [datastore1 (13)] iso/rhel6.4_kickstart.iso. I believe this is due to the special characters. How can I escape these characters before the previously mentioned command, or how can I better achieve this comparison?

Était-ce utile?

La solution

As far as bracket are concerned, you've got the Microsoft official answer in an old Technet Windows PowerShell Tip of the Week.

In you case try :

``[datastore1 (13)``] iso/rhel6.4_kickstart.iso
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top