Ninja Cowgirl
Ninja Cowgirl

Reputation: 11281

powershell find and replace all in one line

I have this line of code which gives me domain\username. However, I need to replace the \ with _. Do I have to do this multiple lines or I can do this in one line?

$UAN = $userProfile["AccountName"].Value
$UAN = $UAN.Replace("/","_")

The above does not work even if it's multiple line.

Upvotes: 0

Views: 3348

Answers (1)

David
David

Reputation: 6561

Use -replace

$UAN = ($userProfile["AccountName"].Value) -replace "\\", "_"

Upvotes: 4

Related Questions