ファイルのコピーをする際に格納フォルダに年月とかつけてほしいという依頼があり、実行日の前日の月などで作ってほしい、という依頼がありました。
コピーだけなのでBATで作ろうとしたのですが、1日前の月などを計算するのがBATでは相当大変そうだったのですが、PowerShellでは結構簡単にできました。
1日前の年
$last_yyyy_str = (Get-Date -Day 1).AddDays(-1).ToString("yyyy")
1日前の年月
$last_yyyymm_str = (Get-Date -Day 1).AddDays(-1).ToString("yyyyMM")
1日前の年月日
$last_yyyymmdd_str = (Get-Date -Day 1).AddDays(-1).ToString("yyyyMMdd")
古めのPowerShellでも動くと思います。
こちらを参考にしたと思います:
https://stackoverflow.com/questions/61189531/powershell-get-date-adddays-how-to-get-desired-format