none
GPO or batch file?

    Question

  • Hello,

    I'm not very good at batch files and wondered if you can help?

    I have a Citrix server where I need to create a nighly batch file or GPO to clear down these folders every night and wondered how I do this?

    There is a profiles folder for Citrix folder where the root shows folders with there userames:

    C:\profiles\

    \Bob

    \Chris

    \Frank

    etc

    Within these folders the have certain areas I need to clean out every night, but I'm not sure how to achive this:

    these are the areas:

    C:\Profiles\User1\UPM_Profile\AppData\Local\Microsoft\Windows\WER\ReportQueue

    C:\Profiles\User1\UPM_Profile\AppData\Roaming\google\cache\Default\Application Cache\Cache

    C:\Profiles\User1\UPM_Profile\AppData\Roaming\google\cache\Default\Pepper Data\*.*

    C:\Profiles\User2\UPM_Profile\AppData\Local\Microsoft\Windows\WER\ReportQueue

    C:\Profiles\User2\UPM_Profile\AppData\Roaming\google\cache\Default\Application Cache\Cache

    C:\Profiles\User2\UPM_Profile\AppData\Roaming\google\cache\Default\Pepper Data\*.*

    etc

    Any ideas?

    Monday, June 22, 2015 10:04 AM

Answers

  • Here is step by step tutorial how to schedule a script.

    http://community.spiceworks.com/how_to/17736-run-powershell-scripts-from-task-scheduler

    Just few recommendations:
    - Use a service account, that will have access to your script and folders you want to remove.- Test your script before and after you schedule it to make sure it works as expected.


    M.

    Monday, June 22, 2015 1:44 PM

All replies

  • I would recommend to schedule a PowerShell script

    you can use something like

    remove-item c:\profiles\*\UPM_Profile\AppData\Local\Microsoft\Windows\WER\ReportQueue
    remove-item "c:\profiles\*\UPM_Profile\AppData\Roaming\google\cache\Default\Application Cache\Cache
    etc...

    Remove-Item explanation: https://technet.microsoft.com/en-us/library/hh849765.aspx
    How to execute a powershell script: https://technet.microsoft.com/en-us/library/ee176961.aspx
    How to schedule a powershell script: http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/11/weekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script.aspx


    M.

    Monday, June 22, 2015 10:29 AM
  • Apologies for my dumb questions (mainly a Network engineer), but Do I just need to open PS and paste this in?

    I've taken a copy of the folder struction to test with first though to be on the save side and have a snapshot.


    • Edited by TB303 Monday, June 22, 2015 11:46 AM
    Monday, June 22, 2015 10:32 AM
  • it's ok - you can open a powershell console and execute commands OR you can change execution policy that will allow you scripts execution and save your commands to .PS1 file and run it from powershell console.

    also - you can run a command remove-item with -whatif parameter, which will show you what it will do without performing an action (removing files).


    M.

    Monday, June 22, 2015 11:42 AM
  • let me test this all out and feed back

    Monday, June 22, 2015 12:58 PM
  • You can save as .ps1 and schedule in task scheduler. First you need set script execution policy to unrestricted.

    Set-ExecutionPolicy Unrestricted -Force

    Monday, June 22, 2015 1:03 PM
  • Do I use inverted comms (")arround the UNC?  one of your examples has it and the other doesn't?
    Monday, June 22, 2015 1:04 PM
  • Hmm just ran this against the 2 profiles I have copied to my PC to test and the files are not removed:

    remove-item "c:\UPM\*\UPM_Profile\AppData\Roaming\google\cache\Default\File System\*.*"

    No errors in the PS windows either


    Monday, June 22, 2015 1:18 PM
  • This helped:

    remove-item "d:\UPM\*\UPM_Profile\AppData\Roaming\google\cache\Default\File System\*" -recurse

    Monday, June 22, 2015 1:29 PM
  • It depends if you want to remove just items in a folder or even in subfolders. -recurse was a good idea. And congratulations - you're becoming a powershell scripter :)


    M.

    Monday, June 22, 2015 1:31 PM
  • Thanks to you!

    I will test further and save as a .ps1 and I guess ude windows task scheduler?

    Monday, June 22, 2015 1:33 PM
  • Also will I need to include Set-ExecutionPolicy Unrestricted -Force in the PS1?
    Monday, June 22, 2015 1:37 PM
  • you can run powershell as an administrator and run set-executionpolicy unrestricted

    It's one time settings - it will also mean, that you will be able to execute other scripts without any restriction.

    After that you will be able to execute and schedule your powershell script.


    M.

    Monday, June 22, 2015 1:42 PM
  • Here is step by step tutorial how to schedule a script.

    http://community.spiceworks.com/how_to/17736-run-powershell-scripts-from-task-scheduler

    Just few recommendations:
    - Use a service account, that will have access to your script and folders you want to remove.- Test your script before and after you schedule it to make sure it works as expected.


    M.

    Monday, June 22, 2015 1:44 PM