5

I have the following line of code...

get-wmiobject -class win32_computersystem | select-object username

It returns (redacted with placeholders)...

@{username=DOMAIN\jsmith}

What needs to be done to remove the padding and give me a "plain" readout of DOMAIN\jsmith?

For bonus points, how do I parse that value into just jsmith?

2 Answers 2

8

You need to expand the property to get the value of username instead of a custom object with the property username. Try

get-wmiobject -class win32_computersystem | select-object -expand username

To get the username only, try:

(get-wmiobject -class win32_computersystem | select-object -expand username).Split("\")[2]

You may need to use [1] instead of [2] at the end depending on your OS. In Windows 8, you need 2, while in Windows 7(and older I think), you need 1.

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

3 Comments

Perfect, it works! Do you happen to know how to tokenize that out to remove the domain portion?
It's a string. It can be split.
Thanks for all of your help everyone. I ended up doing $_.split("\") | select-object -last 1
0

try this

Get-WmiObject -Class Win32_UserAccount | where -property name -eq jsmith | select Name

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.