Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

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

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
ArtiePublic
Asked:
ArtiePublic
1 Solution
 
footechCommented:
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
 
ArtiePublicAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now