Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting VBScript's Replace Function

Windows PowerShell

Definition: Returns a string in which a specified substring has been replaced with another substring a specified number of times.


The world as we know it would come to a crashing halt if we didn’t have search-and-replace commands. In Windows PowerShell you can do a simple search-and-replace on any string value simply by using the -replace parameter and specifying two things:

  • The string value to search for.

  • The replacement text.

For example, the following two command assign a value to the variable $a, then use -replace to replace all instances of the letter x with the letter a:

$a = "bxnxnx"
$a = $a -replace("x","a")

When you run this command and then echo back the value of $a you should get the following:


Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft