gpt4 book ai didi

powershell - 获取远程计算机的用户 SID

转载 作者:行者123 更新时间:2023-12-02 03:05:21 24 4
gpt4 key购买 nike

我正在学习,但不知道如何让下面的代码在远程计算机上运行。

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

最佳答案

您可能正在寻找 Invoke-Command采用 -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 }
}

关于powershell - 获取远程计算机的用户 SID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43110150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com