Quick Hint: Cleaning up File server Public folder using Powershell

Share this:
sans-titre_thumb2_thumb 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%system32WindowsPowerShellv1.0powershell.exe 
  • Add arguments (optional) field
    -NoLogo -NonInteractive -File C:OperationsPF-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.


Written by Anderson Patricio

Anderson Patricio is a Canadian Exchange Server MVP and MCSM (Solutions Master) and he contributes to the Microsoft Community with articles, tutorials, blog posts, forums and book reviews. He is a regular contributor at MSExchange.org, ITPROCentral.com and AndersonPatricio.org (Portuguese).