获取登录用户从计算机名称列表 [英] Get Logged on Users from a List of Computer Names
本文介绍了获取登录用户从计算机名称列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想提取登录到远程PC的用户列表中,PS名称将使用.csv文件喂食。
I wanted to extract a list of users logged on to remote pc, the ps names would be fed in using a .csv file.
我是能够得到一个命令
Get-WmiObject Win32_LoggedOnUser -ComputerName $Computer | Select Antecedent -Unique
查询用户名,可以在任何一个可以帮助我更多关于如何写这个code?
to query the user names, could any one help me more on how to write this code?
推荐答案
假设CSV文件包含一个计算机名头:
Assuming the csv file contains a ComputerName header:
Import-Csv computers.csv | Foreach-Object{
Get-WmiObject Win32_LoggedOnUser -ComputerName $_.ComputerName | Select-Object __SERVER,Antecedent -Unique | Foreach-Object {
$domain,$user = [regex]::matches($_.Antecedent,'="([^"]+)"') | Foreach-Object {$_.Groups[1].Value}
$_ | Select-Object __SERVER,@{Name='Domain';Expression={$domain}},@{Name='User';Expression={$user}}
}
}
这篇关于获取登录用户从计算机名称列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文