[英]How I should get all interactive and remote logon sessions from the remote computer
My task: write a script to get all interactive and remote logon sessions for the selected remote computer.我的任务:编写脚本以获取所选远程计算机的所有交互式和远程登录会话。 And for every session find associated user information.
并为每个会话找到相关的用户信息。
[CmdletBinding()]
param([string]$computername=$env:computername)
function get-logedonuser {
param ($computername)
Get-WmiObject -Class Win32_LogonSession -ComputerName $computername |ForEach-Object {
$data = $_
$id = $data.__RELPATH -replace """", "'"
$q = "ASSOCIATORS OF {$id} WHERE ResultClass = Win32_Account"
Get-WmiObject -ComputerName $computername -Query $q |
Select-Object @{N="User";E={$($_.Caption)}},
@{N="LogonTime";E={$data.ConvertToDateTime($data.StartTime)}}
Get-WmiObject -Query "select * from win32_loggedonuser" | ForEach-Object { (($_.Antecedent -Split "Name=`"")[1] -Split "`"")[0] }
}
}
How should I find all associated user information?我应该如何找到所有相关的用户信息? Could you help me?
你可以帮帮我吗?
使用类Win32_LogonSession
和Win32_Account
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.