こんにちは。 けいぞうです。 今回は「PowerShellでの例外処理の方法 try-catch文とErrorAction」についての記事です。 PowerShellでのtry-catch構文 PowerShellでは他のプログラミング言語と同様にtry-catch文で例外のハンドリングを行うことが可能です。 以下、PowerShellのtry-catchの構文です try { #処理内容 } catch { #例外エラー発生時の処理内容 } finally { #例外の有無に関わらず実行する内容 } 基本的に他の言語と同じですね。 以下、何らかのメール送信処理を例外ハンドリングしたい場合の例文です。 #メール送信処理 try { Send-MailMessage -To "mailto@example.com" -From "mailfrom@example.com" -SmtpServ
![PowerShellでの例外処理の方法 try-catch文とErrorAction | Trend Desk](https://cdn-ak-scissors.b.st-hatena.com/image/square/2c41cfe30e0afbcd909bf8e8f4c9d716a0c611f2/height=288;version=1;width=512/https%3A%2F%2Ftrend-desk.com%2Fwp-content%2Fplugins%2Fall-in-one-seo-pack%2Fimages%2Fdefault-user-image.png)