获取远程计算机

时间:2017-03-30 06:29:52

标签: powershell

我正在学习,无法弄清楚如何让以下代码在远程计算机上运行。

我想在远程计算机上检索特定用户的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 }

2 个答案:

答案 0 :(得分:1)

您可能正在寻找带有-Computername参数的Invoke-Command 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 }
}

答案 1 :(得分:0)

这应该给你:

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

远程:

Get-WmiObject win32_useraccount -ComputerName remotecomputer -Filter "name = 'username' AND domain = 'domainname'" -Credential $cred

Oldschool方法:

wmic useraccount where (name='username' and domain='domainname') get name,sid
相关问题