Vidar
Vidar

Reputation: 41

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.

Upvotes: 1

Views: 5500

Answers (2)

CraftyB
CraftyB

Reputation: 746

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

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

Upvotes: 1

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174815

Either use the member reference operator (.):

(Get-CMDevice -Name AComputerName).UserName

or use Select-Object -ExpandProperty:

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

Upvotes: 1

Related Questions