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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please change the filter to "*.old". That works in my testing.
ASKER
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.
ASKER
thank you very much!
ASKER
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.