Solved

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

Posted on 2014-01-21
2
231 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 39

Accepted Solution

by:
footech earned 500 total points
Comment Utility
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
Comment Utility
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now