Powershell 获取远程计算机的用户SID

Powershell 获取远程计算机的用户SID,powershell,Powershell,我正在学习,不知道如何让下面的代码在远程计算机上工作 我想检索远程计算机上特定用户的SID 下面的代码段用于检索本地计算机上已登录用户的SID。我正在寻找一种方法来使用它来查找远程系统的特定SID。感谢您的帮助 $currentusersid = Get-WmiObject -Class win32_computersystem | Select-Object -ExpandProperty Username | ForEach-Object { ([System.Security.Princi

我正在学习,不知道如何让下面的代码在远程计算机上工作

我想检索远程计算机上特定用户的SID

下面的代码段用于检索本地计算机上已登录用户的SID。我正在寻找一种方法来使用它来查找远程系统的特定SID。感谢您的帮助

$currentusersid = Get-WmiObject -Class win32_computersystem |
Select-Object -ExpandProperty Username |
ForEach-Object { ([System.Security.Principal.NTAccount]$_).Translate([System.Security.Principal.SecurityIdentifier]).Value }

您可能正在寻找采用
-Computername
参数的cmdlet

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 }
}

这应该给你:

[wmi] "win32_userAccount.Domain='domainname',Name='username'"
远程:

Get-WmiObject win32_useraccount -ComputerName remotecomputer -Filter "name = 'username' AND domain = 'domainname'" -Credential $cred
老派方法:

wmic useraccount where (name='username' and domain='domainname') get name,sid

如果您想坚持您的方法,那么遵循Martin的解决方案,这将为您提供远程计算机的支持,前提是应启用PSRemoting。这将返回AD计算机的SID,而不是登录到该计算机的用户的SID(提问者问到这一点)。是的。我忽略了这个问题谢谢你们。正是我所需要的。