Link to home
Start Free TrialLog in
Avatar of xouvang
xouvang

asked on

What powershell script to remove folder weekly?

Hi all,

I'm new to powershell and learning as I go as a JR Sys Admin. Currently looking for powershell classes to take locally but limited in AK. (Also if you're from AK and know any local class or teach powershell please let me know)

I want to run this script weekly

What I need it to do is remove folders with the file name ".old" in a certain directory.
Let's say on server1 in the C\Users there are a few profiles that had to be rebuilt and the old ones were renamed to xxx.old. Is there a script to go in and remove any folder that has the .old?

I have 7 servers, I was wondering if one script can go into those 7 servers and remove them.


Thanks
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xouvang
xouvang

ASKER

I'm testing the powershell script and it's not working.
Before I do it on thes server I'm testing it on a local machine.

So far the command works  up to Get-ChildItem \\$server\c$\Users. After the filter, nothing comes back.
Below is a screen shot of the command.

Sorry again, I'm still learning.

User generated image
Please change the filter to "*.old".  That works in my testing.
Avatar of xouvang

ASKER

Thank you that worked.

The command works but it's not removing the folder. The folder is still there. Is there another command I need to run?
Attached is the powershell screenshot

User generated image
Yes, as I mentioned in my first post, remove the -whatif parameter from Remove-Item to run for real.  I included that so you could see what it was going to do without actually removing anything.
Avatar of xouvang

ASKER

thank you very much!