如何获取 windows 服务器的登录 user/users?
How to get the logged on user/users of a windows server?
对于台式机,我使用 win32_computersystem wmi class 并只阅读 "username",但在 windows 服务器上这是空白。
此外,客户端上只能有一个活动会话,而服务器可以有多个人登录 - 假设这是我无法使用相同 class 获取它的部分原因.
如何获取服务器的当前登录user/users?
试试这个
$computer = 'MyServer1'
$owners = @{}
gwmi win32_process -computer $computer -Filter 'name = "explorer.exe"' | % {$owners[$_.handle] = $_.getowner().user}
get-process -computer $computer explorer | % {$owners[$_.id.tostring()]}
或者这个
https://gallery.technet.microsoft.com/scriptcenter/Get-LastLogon-Determining-283f98ae
对于台式机,我使用 win32_computersystem wmi class 并只阅读 "username",但在 windows 服务器上这是空白。
此外,客户端上只能有一个活动会话,而服务器可以有多个人登录 - 假设这是我无法使用相同 class 获取它的部分原因.
如何获取服务器的当前登录user/users?
试试这个
$computer = 'MyServer1'
$owners = @{}
gwmi win32_process -computer $computer -Filter 'name = "explorer.exe"' | % {$owners[$_.handle] = $_.getowner().user}
get-process -computer $computer explorer | % {$owners[$_.id.tostring()]}
或者这个
https://gallery.technet.microsoft.com/scriptcenter/Get-LastLogon-Determining-283f98ae