我正在尋找一種方法來殺死斷開終端會話的.exe。這是關於Navision的;我們擁有有限的許可證,並希望繼續殺死那些未使用的許可證。PowerShell腳本殺死.exe終端服務器斷開會話
我知道有方法可以完全註銷斷開連接的會話,但我更願意只關閉這個特定的進程。
我確實發現了一篇博文,其中描述了我正在尋找的代碼。一個powershell腳本,用於在斷開連接的會話中掃描某個.exe文件,並將其關閉。 http://www.interworks.com/blogs/jpoehls/2012/12/12/killing-processes-disconnected-terminal-service-sessions該代碼發佈在此網頁上。
遺憾的是它不工作,我得到以下錯誤:
PS C:\scripts> .\navscript.ps1
An empty pipe element is not allowed.
At C:\scripts\navscript.ps1:91 char:10
+ | <<<< % { $id = $_;
+ CategoryInfo : ParserError: (:) [
+ FullyQualifiedErrorId : EmptyPipeElement
而且很多的花費在谷歌找到不同的解決方案的時候,我也試過在第90行。這導致刪除空行在另一個錯誤:
PS C:\scripts> .\navscript.ps1
Exception calling "Substring" with "2" argument(s): "Lengte kan niet minder dan nul zijn.
Parameternaam: length"
At C:\scripts\navscript.ps1:52 char:44
+ ;"ID" = $line.Substring <<<< ($line.IndexOf(" ", $starters.Username), $starters.ID - $line.IndexO
f(" ", $starters.Username) + 2).trim()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
我希望有人有一個想法如何得到這個工作。