Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


August 06, 2009

Delete Junk Folders Created by SMS

PowerShell script makes it easy to find and delete them
RSS
Subscribe to Windows IT Pro | See More Systems Management Server (SMS) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

As the result of a few wrong switches, Microsoft Systems Management Server (SMS) created but didn't delete some folders on many computers at my company. For example, the folders highlighted in Figure 1 were some of the folders added to one machine.


Figure 1: Example of folders created but not deleted by SMS


Because the folders created by SMS didn't have Full Control Administrators permission applied, deleting those folders involved:

  • Logging on to each machine locally or remotely.
  • Applying Full Control Administrators permission to each folder. Without this permission, the folders can't be deleted by administrators.
  • Deleting the folders.

Manually performing these steps would've been time-consuming, so I wrote a PowerShell script, deljunkfolders.ps1, to automatically delete the folders and their contents. All the folders contained a subfolder named update, like that in Figure 2. So, deljunkfolders.ps1 looks for subfolders named update in top-level directories.


Figure 2: Looking for an update subfolder in top-level folders


After finding all the top-level folders that contain an update subfolder, deljunkfolders.ps1 uses the Get-Acl cmdlet to copy permissions from a folder where the administrators have Full Control Administrators permission, then uses the Set-Acl cmdlet to apply that permission to the folder that needs to be deleted. Finally, the script either displays the folders to be deleted or deletes them, depending on the command you use to launch the script.

If you want to preview the folders that will be deleted and deljunkfolders.ps1 resides on the D drive, you'd use a command such as

Powershell.exe D:\deljunkfolders.ps1 Pclist.txt

Pclist.txt is an input file that contains the names of the computers you want to check. When you create this text file, the computer names need to follow format

Pc001
Pc002
Pc003

If you're happy with the results in the preview, you can perform the actual deletion using a command such as

Powershell.exe D:\deljunkfolders.ps1 Pclist.txt 1

The last argument (1) tells the script to delete the folders. Note that if a computer is unavailable, the script returns a message stating that the ping failed for that computer.

You can download deljunkfolders.ps1 by clicking the Download the Code Here button at the top of the page. Using this script as a template, you can create your own solution to delete folders that SMS created but didn't delete. I used PowerShell 1.0 to create this script, which I tested on Windows XP.

End of Article



Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...


Related Articles Use PowerShell to Execute Commands on Remote Machines

4 Ways to Help PowerShell Find External Tools

PowerShell 101, Lesson 1

PowerShell Script Lets You Check Patches' Status

Task Automation Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

PowerShell 201 - eLearning Series with Paul Robichaux

7 Ways To Get More From Your SharePoint Deployment Now

Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement