0

Using function i'm getting output like this:

User                                                                                                         
----                                                                                                         
Domain\Username

But when I'm trying to replace the "Domain\" in output

$f -replace 'Domain\\'

I'm getting this:

@{User=Username}

I'm using bad function or is something else is going wrong?

1
  • 2
    $f.User=$f.User -replace 'Domain\\';$f Commented Dec 25, 2015 at 10:57

2 Answers 2

2

Try this:

$f.User -replace 'Domain\\', ''

instead of this -

$f -replace 'Domain\'

Your output from your variable is showing you the answer. You had an object with a user property as supposed to the string you thought you were working on.

Sign up to request clarification or add additional context in comments.

Comments

1

Your output is an object with a property User. If you just use -replace on the object you're basically converting the object to a string (@{User=Domain\Username}) and replacing Domain\ in that string. Use the operator on the property User to remove the substring from the value of that property:

$f.User -replace 'Domain\\'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.