6

#PSTip Convert a path to WMI compatible path

Note: This tip requires PowerShell 3.0 or above.

Some of the WMI queries require that we specify the folder path with an escaped path separator. For example, take a look at the following error.

cimerror

So, we need to escape the path separator for the above query to work.

cimnoerror

When we are running such queries programmatically for user provided input, we need a better way to convert the path to WMI compatible path.

Here is the trick I use.

'C:\Windows' -replace "\\","\\"

How do you do it?

Filed in: Columns, Tips and Tricks Tags: , , , ,
© 6789 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: