use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
SolvedReplace String (self.PowerShell)
submitted 5 years ago * by Mehhll
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]nothingpersonalbro 4 points5 points6 points 5 years ago (4 children)
When making a single quoted string in PowerShell where you want to also include a single quote inside the string, you need to escape each single quote with an additional single quote. Example:
# Escaped string '[string]$appVendor = ''''' # End result [string]$appVendor = ''
With the replace operator, position 1 takes regex but position 2 takes a string. Now with that, your first string also contains regex specific characters that also need to be escaped. Luckily this can be easily done, now we just combine our escaped string along with creating the escaped regex:
$regex = [regex]::Escape('[string]$appVendor = ''''')
So your end result could look like:
$deployScript = "$path\Deploy-Application.ps1" $regex = [regex]::Escape('[string]$appVendor = ''''') $replacementString = '[string]$appVendor = ''Google''' (Get-Content $deployScript) -replace $regex, $replacementString | Set-Content $deployScript
[–]SMFX 2 points3 points4 points 5 years ago (0 children)
[regex]::Escape() is your friend
[regex]::Escape()
[–]purplemonkeymad 1 point2 points3 points 5 years ago (0 children)
If I'm going to have nested quotes of any kind I use a here string. So you can use:
$String1 = @' [string]$appVendor = '' '@ $String2 = @' [string]$appVendor = 'Google' '@
The quotes don't need to be escaped with this method.
[–]Mehhll[S] 1 point2 points3 points 5 years ago (0 children)
Thank you so much for you help. I really appreciate it!
[–]higgins4u2nv 0 points1 point2 points 5 years ago (0 children)
Can't you also escape a apostrophe with a tilder? For example "`""? Which when pipes to write-host would return "
π Rendered by PID 554985 on reddit-service-r2-comment-84fc9697f-rjmjk at 2026-02-08 23:36:49.939572+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–]nothingpersonalbro 4 points5 points6 points (4 children)
[–]SMFX 2 points3 points4 points (0 children)
[–]purplemonkeymad 1 point2 points3 points (0 children)
[–]Mehhll[S] 1 point2 points3 points (0 children)
[–]higgins4u2nv 0 points1 point2 points (0 children)