Home > Net >  Powershell command to select one value
Powershell command to select one value

Time:10-12

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

CodePudding user response:

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
  • Related