Вопрос

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?

Это было полезно?

Решение

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top