开发者

Get Logged on Users from a List of Computer Names

I wanted to extract a list of users logged on to remote pc, the ps names would be fed in using a .csv file.

I was able to get a command

Get-WmiObject Win32_LoggedOnUser -ComputerName $Computer | Select 开发者_JAVA技巧Antecedent -Unique

to query the user names, could any one help me more on how to write this code?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜