Reputation: 151
I am trying to write a PS script to find a share named C$$ but PS is interpreting the $ sign and I want to pass it into the filter. Normally \ stops this but after googling I cant get a working solution.
$string = "Name='C\$\$'"
Write-Host $string
get-wmiobject -Class Win32_share -filter $string
The write host returns Name='C\$\$' I need it to return C$$
Upvotes: 11
Views: 16327
Reputation: 32145
There's several ways to do this. Note in the first one that you only need to escape the first $
.
$string = "Name='C`$$'"
$string = "Name='C$$'"
$string = 'Name=''C$$'''
$string = "Name='C{0}'" -f '$$'
$string = @'
Name='C$$'
'@
$string = @"
Name='C`$$'
"@
Upvotes: 4
Reputation: 1870
You can use the backtick to escape characters in a string.
$string = "Name='C`$`$'"
That should return Name='C$$'
Upvotes: 16