Get-Dateコマンドレットを利用して本日が月末かどうかの判定をするPowerShellスクリプトを書いてみました。
月末判定を行うPowerShellスクリプトのサンプルを記します。
以下の処理は、本日に+1日し、翌日の日付が1日だった場合、月末として判定しています。
if ( (Get-Date).AddDays(1).Day -eq 1 ) {
Write-Host (Get-Date).ToString('yyyy-MM-dd') is end of month.
}
else {
Write-Host (Get-Date).ToString('yyyy-MM-dd') is *NOT* end of month.
}
月末と月末以外の日付で月末判定スクリプトを実行してみたときの出力です。
PS C:\Users\sakura\Desktop> (Get-Date).ToString('yyyy-MM-dd')
2012-05-23
PS C:\Users\sakura\Desktop> C:\Users\sakura\Desktop\eom.ps1
2012-05-23 is *NOT* end of month.PS C:\Users\sakura\Desktop> (Get-Date).ToString('yyyy-MM-dd')
2012-05-31
PS C:\Users\sakura\Desktop> C:\Users\sakura\Desktop\eom.ps1
2012-05-31 is end of month.