Hi,
也许你可以尝试下这个脚本。
脚本中含有三个参数分别是-computer –all –ou。
-computer参数中是获取特定电脑的登陆用户,-ou是搜索此OU运行中所有计算机的所有登录用户,最后一个参数-all提供包含前两个所有的信息。
function Get-UserLogon {
[CmdletBinding()]
param
(
[Parameter ()]
[String]$Computer,
[Parameter ()]
[String]$OU,
[Parameter ()]
[Switch]$All
)
$ErrorActionPreference="SilentlyContinue"
$result=@()
If ($Computer) {
Invoke-Command -ComputerName $Computer -ScriptBlock {quser} | Select-Object -Skip 1 | Foreach-Object {
$b=$_.trim() -replace '\s+',' ' -replace '>','' -split '\s'
If ($b[2] -like &#