Empty Recycle Bin
If you are machine running on PowerShell 5.0, you can use “Clear-RecycleBin” cmdlet.
Since Windows 7 native PowerShell is 2.0 only, we cannot use the PowerShell 5.0 cmdlet to clear recycle bin, we change to use “Clear-RecycleBinItems.ps1” (https://thinkpowershell.com/powershell-script-empty-recycle-bin-logoff/)
Then, we create a GPO under User Configuration and apply to user OU
Since the PowerShell from GPO cannot run if we did not change Windows PowerShell Policy by the following GPO, the fast way is change the execution policy to “allow local scripts and remote signed scripts” and apply to machine OU
Delete files under specific folder when logoff
Batch file for delete file and GPO apply to user OU
Example:
:echo off
cmd.exe /c "echo Y|PowerShell.exe -NoProfile -Command Remove-item c:\Documents\*.* -Force"
cmd.exe /c "echo Y|PowerShell.exe -NoProfile -Command Remove-item c:\Documents\MYMUSI~1\*.* -Force"
cmd.exe /c "echo Y|PowerShell.exe -NoProfile -Command Remove-item c:\Documents\MYPICT~1\*.* -Force"
cmd.exe /c "echo Y|PowerShell.exe -NoProfile -Command Remove-item c:\Documents\MYVIDE~1\*.* -Force"
cmd.exe /c "echo Y|PowerShell.exe -NoProfile -Command Remove-item c:\Documents\download\*.* -Force"
exit
Reference:
https://thinkpowershell.com/powershell-script-empty-recycle-bin-logoff/
https://www.jaapbrasser.com/clear-recyclebin-new-powershell-5-0-cmdlet-available-in-windows-10/
http://baldwin-ps.blogspot.hk/2013/07/empty-recycle-bin-with-retention-time.html
https://4sysops.com/archives/powershell-versions-and-their-windows-version/
No comments:
Post a Comment