Get Username from Computer Name Using Powershell and Sccm

Get Username from Computer Name Using Powershell and Sccm

I'm attempting to do the following :

Query SCCM using Powershell for a computer name, then, within the output of that, get the UserName.

Right now, I am using :

Get-CMDevice -name <computername>

This returns the entire record. Within that is an item called "UserName". That's what I want to extract out.

It's been a very long time since working with powershell, let alone the SCCM plugins.

2 Answers

Either use the member reference operator (.):

(Get-CMDevice -Name AComputerName).UserName

or use Select-Object -ExpandProperty:

Get-CMDevice -Name AComputerName |Select-Object -ExpandProperty UserName

You should just be able to put the command in brackets and select the property directly as shown below:

(Get-CMDevice -name <computername>).UserName

Your Answer

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

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.