在PowerShell中获取当前Windows会话ID
每个Win32_进程对象都包含一个SessionId字段。在PowerShell中获取当前Windows会话ID的最简单方法是什么?我所说的current是指运行脚本的会话。我希望避免解析在PowerShell中获取当前Windows会话ID,powershell,Powershell,每个Win32_进程对象都包含一个SessionId字段。在PowerShell中获取当前Windows会话ID的最简单方法是什么?我所说的current是指运行脚本的会话。我希望避免解析查询会话命令的输出。如果无法实现,是否可以列出当前会话中的所有进程?您应该能够使用: (Get-Process -PID $pid).SessionID 你可以 PS C:\Users\AlexK> [System.Diagnostics.Process]::GetCurrentProcess().Se
查询会话
命令的输出。如果无法实现,是否可以列出当前会话中的所有进程?您应该能够使用:
(Get-Process -PID $pid).SessionID
你可以
PS C:\Users\AlexK> [System.Diagnostics.Process]::GetCurrentProcess().SessionId
1
我也很好奇,但如果您陷入困境,您可以使用我的答案将
qwinsta
中的数据解析为PowerShell对象。