 |
How can I clean up my File Server Public folder directory on an interval basis using PowerShell?
If your company uses a Public folder and your policy is to clean up every X days you can use PowerShell to do the work for you. Let’s create a folder on the C: root called Operations and save the command line below in a file called PF-clean.ps1. Make sure to change the path for your public folder.
Remove-Item -Path F:\Public\* -Recurse
Now it comes the easy part, just create new Windows Task and make sure to fill out these following fields when they show up:
- Program/Script field
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
- Add arguments (optional) field
-NoLogo -NonInteractive -File C:\Operations\PF-clean.ps1
Finally, during the general tab you can configure the service to run when your user is not logged on by configuring the settings shown in the figure below:

Note: Depending of your environment you may have to run Set-ExecutionPolicy –ExecutionPolicy Unrestricted if your scripts are not signed.
|
Cheers,
Anderson Patricio
http://www.andersonpatricio.ca
http://www.andersonpatricio.org (Portuguese)
Twitter: @apatricio