SmartestVEGA
SmartestVEGA

Reputation: 8899

Powershell command to select one value

My PowerShell command is working fine as below :

PS C:\Users\username> whoami /user

USER INFORMATION
----------------

User Name        SID
================ ==============================================
wip\username     S-1-5-21-57989841-616248376-1811674531-4551702

But when I try to select only SID, it is showing blank

PS C:\Users\username> whoami /user | Select-Object "User information"

User information
----------------
blank

I am expecting "S-1-5-21-57989841-616248376-1811674531-4551702" instead of blank

Upvotes: 1

Views: 896

Answers (2)

Peter
Peter

Reputation: 183

It is also possible to remove header and manipulate with the result as we know it's format and structure.

The following command prints an SID of the first user in the list:

(whoami /user /nh).Split(" ")[1]

In case of many users you have to select the line by username first.

Upvotes: 0

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174825

whoami is not a PowerShell cmdlet - it's an executable - so the output is text, not an object you can manipulate with Select-Object.

You can get your current SID from:

[System.Security.Principal.WindowsIdentity]::GetCurrent().User

Upvotes: 2

Related Questions