Ci sono due modi per fare il replace di stringhe in PowerShell. Invocare il metodo Replace(str1, str2) dell'oggetto stringa

PowerShell

$a = "tesT"
$a.Replace("t", "x")
che da come risultato

Text

xesT
quindi fa un replace case sentitive, oppure usare il parametro -replace di PowerShell

PowerShell

$a = "tesT"
$a -replace "t", "x"
# oppure $a -replace("t", "x")
che da come risultato

Text

xesx
che esegue un replace case insensitive. Il vantaggio del parametro -replace è che accetta anche delle regual expression.
Per renderlo case sensitive anteponi una c ovvero -creplace

PowerShell

$a -creplace "t", "x"

Per maggiori info digita

PowerShell

get-help about_Comparison_Operators | more
Tags:
PowerShell199 Script85
Potrebbe interessarti anche: