Solved

Deleting a folder across the domain on the Root of C, using Powershell

Posted on 2014-01-21
2
234 Views
Last Modified: 2014-01-29
Hi, not sure if its even possible but we have an Exchange OAB issue and need to delete 2 folders within the c:\users\*UserName*\AppData.... directory. I can do this by specifying the computer i want to do this to, but can i do this for all computer names within the domain? I'm sure i would have to call a user.txt file containing our usernames or something.

Any thoughts?

Thanks!
0
Comment
Question by:ArtiePublic
2 Comments
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39798477
You would only need a file for usernames if you want to restrict the operation to those usernames (or exclude them).

It would be more likely that you would need a list of computers that you want to apply this to.  If you don't have that then you could query Active Directory for computer accounts.  You might have to filter that query so that it only returns the machines you're interested in.  I'm assuming you are able to use MS's AD cmdlets.

It would be even better (i.e. much faster) if you were using PowerShell Remoting, but I'll give a script that can handle this just using UNC paths.  You just have to get the parameters right for Get-ChildItem so that it finds the right folders to delete.  Without knowing those paths, I'm giving some generic samples.  I've also included the -whatif parameter so that nothing will actually be removed if you run the script, it will just display a message.
Import-Module ActiveDirectory
Get-ADComputer -Filter * | Select -expand Name | ForEach `
{
    Get-ChildItem \\$_\C$\Users\*\AppData -Recurse -Force -Filter "outlook" -ErrorAction SilentlyContinue |
     Where {$_.PsIsContainer -eq $true} |
     Remove-Item -Recurse -Force -WhatIf
    Get-ChildItem \\$_\C$\Users\*\AppData -Recurse -Force -Filter "anotherfolder" -ErrorAction SilentlyContinue |
     Where {$_.PsIsContainer -eq $true} |
     Remove-Item -Recurse -Force -WhatIf
}

Open in new window

0
 

Author Comment

by:ArtiePublic
ID: 39817998
Sorry for the late reply, we spent a few days on this and this definitely got us to where we needed to be and its now working.

Thank you
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question