Removing Empty Folders

There’s a “feature” in ConfigMgr 2012 that occurs when you perform the following steps:

  • Send a package to the DP
  • Enable the “Copy the content in this package to a package share on distribution points” checkbox.
  • Clear the “Copy the content in this package to a package share on distribution points” checkbox.

When you clear the checkbox, the contents of the folder on the share are removed, but the root folder (which is named by PackageID) remains.

Normally this wouldn’t be a problem, but we do have a 3rd party integration  to ConfigMgr 2012 that will look for packages on the package share, and since these are empty, we receive unexpected results.  As a result, here’s a simple PowerShell script to remove any empty folders from the smspkgd$ share:


get-childitem d:\smspkgd$  | % { if ((get-childitem -path $_.FullName -recurse | measure-object -property length -sum).sum -eq $null) {$_.Name; remove-item -path $_.FullName}}

Happy Scripting!

Unknown's avatarAbout Greg Ramsey
Greg Ramsey is a Senior Distinguished Engineer for Dell Digital - Services. He has a B.S. in Computer Sciences and Engineering from The Ohio State University and has co-authored many books over the years. Greg is also a board member of the Northwest System Center User Group and the Midwest Management Summit. ​Greg has been a Microsoft Endpoint Manager (ConfigMgr, Intune) MVP for over 18 years.

Leave a comment