Get user id on remote computer
I am learning and cannot figure out how to get the below code to work on a remote machine.
I want to get the SID of a specific user on a remote computer.
Below is a snippet of work to get the SID of a logged in user on a local computer. I'm looking for a way to use this to find a specific SID for a remote system. Any help is appreciated.
$currentusersid = Get-WmiObject -Class win32_computersystem |
Select-Object -ExpandProperty Username |
ForEach-Object { ([System.Security.Principal.NTAccount]$_).Translate([System.Security.Principal.SecurityIdentifier]).Value }
+3
source to share
2 answers
This should give you:
[wmi] "win32_userAccount.Domain='domainname',Name='username'"
Remotely:
Get-WmiObject win32_useraccount -ComputerName remotecomputer -Filter "name = 'username' AND domain = 'domainname'" -Credential $cred
Oldschool Method:
wmic useraccount where (name='username' and domain='domainname') get name,sid
0
source to share
You are probably looking for a cmdlet Invoke-Command
that takes a parameter -Computername
.
Invoke-Command -ComputerName 'whatever' -ScriptBlock {
$currentusersid = Get-WmiObject -Class win32_computersystem |
Select-Object -ExpandProperty Username |
ForEach-Object { ([System.Security.Principal.NTAccount]$_).Translate([System.Security.Principal.SecurityIdentifier]).Value }
}
+1
source to share