?
Solved

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

Posted on 2014-01-21
2
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
footech earned 2000 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

765 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