2015-05-07 69 views
1

每個Win32_Process對象都包含一個SessionId字段。在PowerShell中獲取當前Windows會話ID的最簡單方法是什麼?目前我指的是腳本運行的會話。我想避免分析query session命令的輸出。如果這不可行,是否可以列出當前會話中的所有進程?在PowerShell中獲取當前Windows會話ID

+0

我也很好奇,但如果您遇到問題,你可以使用我的答案[這裏](HTTP://計算器.com/a/29130697/3829407)將數據從'qwinsta'解析到PowerShell對象中。 – Matt

回答

4

您應該能夠使用:

(Get-Process -PID $pid).SessionID 
4

可以

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