ユーザーがpowershellスクリプトを中断したときにキャッチする方法はありますか.
PSSession を終了する必要があります。
try finally を使用してテストしましたが、スクリプトが中断されたときに finally が実行されませんCtrl+c
try
{
$s = New-PSSession -ComputerName MYCOMPUTER -Credential (Get-Credential -Credential admin )
Invoke-Command -ScriptBlock { Get-EventLog -LogName Application } -Session $s
}
catch [Exception]
{
}
finally
{
echo "Ending the session"
Remove-PSSession $s
}