Windowsのログアウト(サインアウト)時にごみ箱を空にする


容量にシビアなサービス

ディスク容量を増やす前、削れるところは削ること。クラウドサービスは増やしたら簡単に減らせない。
ログイン・アウト時、実行する仕組みはいろいろカスタム処理で愛用している。

グループポリシー

ユーザの構成→ポリシー→Windwosの設定→スクリプトーログイン->プロパティ(PowerShellスクリプト)
\{ADサーバ}\sysvol\hoge.local\scripts\RemoveItem-Recyclebin.ps1

スクリプト

RemoveItem-Recyclebin.ps1
function RemoveItem-Recyclebin {
    $Shell = New-Object -ComObject Shell.Application;
    $RecycleBin = $Shell.Namespace(0xA);
    $RecycleBin.Items() | ForEach-Object { Remove-Item $_.Path -Recurse -Confirm:$false }
}
RemoveItem-Recyclebin

参考

PowerShell – ごみ箱を空にする方法