我想请求一些关于在终端会话(如 Citrix)上查找用户的帮助。我已经浏览过这个论坛上关于“终端会话”的大部分问题。不幸的是,没有什么能真正帮助我 :(
我尝试搜索get-PSterminalsessions
(http://psterminalservices.codeplex.com),但是我按照给出的步骤操作后,该模块没有加载。我在 Win 7 和 2008 R2 上尝试过。
当我尝试使用invoke-expressions -command "Quser xyz"
它时,它没有返回任何东西。
答案1
从 powershellcommunity.org 脚本存储库尝试此操作:
Function Get-ComputerSession {
<#
.SYNOPSIS
Retrieves all user sessions from local or remote server/s
.DESCRIPTION
Retrieves all user sessions from local or remote server/s. Requires query.exe in order to run properly.
.PARAMETER computer
Name of computer/s to run session query against.
.NOTES
Name: Get-ComputerSession
Author: Boe Prox
DateCreated: 01Nov2010
.LINK
https://boeprox.wordpress.org
.EXAMPLE
Get-ComputerSessions -computer "server1"
Description
-----------
This command will query all current user sessions on 'server1'.
#>
[cmdletbinding(
DefaultParameterSetName = 'session',
ConfirmImpact = 'low'
)]
Param(
[Parameter(
Mandatory = $True,
Position = 0,
ValueFromPipeline = $True)]
[string[]]$computer
)
Begin {
$report = @()
}
Process {
ForEach($c in $computer) {
# Parse 'query session' and store in $sessions:
$sessions = query session /server:$c
1..($sessions.count -1) | % {
$temp = "" | Select Computer,SessionName, Username, Id, State, Type, Device
$temp.Computer = $c
$temp.SessionName = $sessions[$_].Substring(1,18).Trim()
$temp.Username = $sessions[$_].Substring(19,20).Trim()
$temp.Id = $sessions[$_].Substring(39,9).Trim()
$temp.State = $sessions[$_].Substring(48,8).Trim()
$temp.Type = $sessions[$_].Substring(56,12).Trim()
$temp.Device = $sessions[$_].Substring(68).Trim()
$report += $temp
}
}
}
End {
$report
}
}