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:

image

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

Anderson Patricio is a Canadian MVP in Cloud and Datacenter Management, and Office Server and Services, besides the Microsoft Award he also holds a Solutions Master (MCSM) in Exchange and several other certifications. Anderson has been contributing to the Microsoft Community with articles, tutorials, blog posts, twitter, forums and book reviews. He is a regular contributor here at ITPROCentral.com, MSExchange.org, Techgenix.com and Anderson Patricio.org (Portuguese).