Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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.
Changing a few Outlook Options can help keep you organized!
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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