locked
Deleteing folder for multiple users RRS feed

  • Question

  • Good morning all -

    As most people would admit, I am terrible at scripting in any form.  In short, I need assistance with a dummy proof script to delete the contents of a folder for multiple (150+) users, without  having to touch each users profile.  I would prefer to be able to execute the script when needed.  This won't be listed as a scheduled task or setup as a netlogon. The path is as follows:

    C:\Users\michael.jannise.ctr\NS5\tmp

    It can either be set to delete the tmp folder entirely, or just the contents of the folder.  Which ever is easier. 

    I would greatly appreciate any assistance provided!

    Regards,

    Michael

    Friday, June 13, 2014 3:38 PM

Answers

All replies

  • Hi Michael,

    PowerShell makes this quite easy:


    Remove-Item -Path 'C:\Users\*\NS5\tmp' -Recurse -WhatIf



    EDIT: Link to syntax:

    http://ss64.com/ps/remove-item.html


    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    • Edited by Mike Laughlin Friday, June 13, 2014 3:43 PM
    • Proposed as answer by jrv Friday, June 13, 2014 3:44 PM
    • Marked as answer by mjannise Friday, June 13, 2014 4:01 PM
    Friday, June 13, 2014 3:42 PM
  • Thanks, Mike!

    Just to make sure I'm am crystal clear in your explanation, I can copy that line into a .ps1 file and execute?

    Friday, June 13, 2014 3:45 PM
  • Yep, or you can just paste it directly into the console.

    EDIT: Which version of PowerShell are you running? Remove-Item had some issues pre-V3.


    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    Friday, June 13, 2014 3:56 PM
  • Thank you very much!  I will test it and let you know if there are any issues!

    Thanks, Mike!

    Friday, June 13, 2014 4:01 PM
  • Friday, June 13, 2014 4:04 PM
  • Well, Mike. 

    back to the drawing board, it didn't seem to work for me.  After copying the line into Powershell, you can see the output in the picture.  Any ideas?

    Friday, June 13, 2014 4:19 PM
  • Friday, June 13, 2014 4:20 PM
  • =]

    That's because you still have -WhatIf in the command.

    The -WhatIf switch is used as a safeguard. If you're happy with having those two folders deleted, remove the -WhatIf switch and run the command again.


    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    Friday, June 13, 2014 4:22 PM
  • I told you I was an amateur! :)

    The only folder that should be deleted is the tmp folder within the NS5 folder. 

    C:\Users\michael.jannise.ctr\NS5\tmp

    The NS5 directory should stay intact.

    Friday, June 13, 2014 4:26 PM
  • You should be good to remove -WhatIf then. The tmp folder will be deleted for both of those users.


    EDIT: Have you seen the learning resources available here yet? They're quite good for getting started with PowerShell:

    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx


    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    Friday, June 13, 2014 4:29 PM
  • I was going to warn you but this is more fun.

    Understanding Windows and the Windows file system is always a big problem for non-technicians.

    Learning this technology requires some time for testing things until you understand how they work. You really cannot learn this by asking people on the Internet to give you answers.

    The command, as posted. removes only the "tmp" folder contents. How to make that clear is not clear. It needs to be tried. THe safe way yo do thisis to make a parallel structure and test that.


    ¯\_(ツ)_/¯

    Friday, June 13, 2014 4:32 PM
  • I was going to warn you but this is more fun.

    Understanding Windows and the Windows file system is always a big problem for non-technicians.

    Learning this technology requires some time for testing things until you understand how they work. You really cannot learn this by asking people on the Internet to give you answers.

    The command, as posted. removes only the "tmp" folder contents. How to make that clear is not clear. It needs to be tried. THe safe way yo do thisis to make a parallel structure and test that.


    ¯\_(ツ)_/¯

    Well, I can play the game!  :)  I know I should spend the time working with this type of technology but, I would not execute it day to day and would most likely still make mistakes. 

    I am extremely grateful for people like yourselves who are willing to share the knowledge!

    Friday, June 13, 2014 4:39 PM
  • Are you saying you do not work with Windows everyday?  If you do not use Windows I can understand.

    I wasn't really poking at you but at Mike because these simpl quesiotns are only asked by non-techs usually.  His answer was exact and easy but it was clear that it could not be understood.

    I posted to push you towards spending time learning he very basics of Windows.  If you are doing to delete files in  the profiles or run as an Admin you must learn these things to avoid serious disasters.

    Deleting files and folders is a basic computer skill. 

    Anyway - don't worry about it.  It is just my way of making a suggesting that sticks.


    ¯\_(ツ)_/¯

    Friday, June 13, 2014 4:53 PM
  • I wasn't really poking at you but at Mike

    =]

    Everybody's gotta start somewhere. Plus, quick hit threads like these work nicely for me while I'm waiting for ConfigMgr to finish processing update deployments.


    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    Friday, June 13, 2014 5:27 PM
  • I take absolutely no offense to any of it.  In fact, I assume some poking is always warranted! :)

    Like I said ealier, all the help is greatly appreciated! 

    Best Regards!

    Michael

    Friday, June 13, 2014 5:30 PM
  • Mike - Yeah - ConfigMgr makes things boring.   I used to do a room full on installs of large servers and still got bored.  I no leave all of that to the grunts if I can.

    Michael - pop the hood and take a close look at the engine.  It is really cool.


    ¯\_(ツ)_/¯

    Friday, June 13, 2014 5:48 PM