Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PowerShell中获取当前Windows会话ID_Powershell - Fatal编程技术网

在PowerShell中获取当前Windows会话ID

在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

每个Win32_进程对象都包含一个SessionId字段。在PowerShell中获取当前Windows会话ID的最简单方法是什么?我所说的current是指运行脚本的会话。我希望避免解析
查询会话
命令的输出。如果无法实现,是否可以列出当前会话中的所有进程?

您应该能够使用:

(Get-Process -PID $pid).SessionID
你可以

PS C:\Users\AlexK> [System.Diagnostics.Process]::GetCurrentProcess().SessionId
1

我也很好奇,但如果您陷入困境,您可以使用我的答案将
qwinsta
中的数据解析为PowerShell对象。