question

BelgianMalinois avatar image
1 Vote"
BelgianMalinois asked saldana-msft edited

Delete Empty folders in SCCM console?

I have several hundred of empty folders under both the application node and packages nodes under Application Management
Any way to mass delete them? I could not find any cmdlet that I could think of

mem-intune-generalmem-cm-co-management
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SunnyNiu-MSFT avatar image
1 Vote"
SunnyNiu-MSFT answered RogerHendrikse-7977 commented

@BelgianMalinois
We could find the empty folders under the applications node in WMI Explorer through the following query:

 SELECT * FROM SMS_ObjectContainerNode 
 where ObjectTypeName='sms_applicationlatest'

We could find the empty folders under the packages node in WMI Explorer through the following query:

 SELECT * FROM SMS_ObjectContainerNode 
 where ObjectTypeName='sms_package ' 

Here is the PowerShell script to delete the empty folders under the applications node(please replace the SiteCode and SiteServerName with yours):

 $ab = Get-WmiObject -Namespace “root\sms\site_xxx(SiteCode)” -ComputerName 'xxx(SiteServerName)' -Query "SELECT * FROM SMS_ObjectContainerNode 
 where ObjectTypeName='sms_applicationlatest'  and IsEmpty = 1 "
 $ab | remove-wmiobject

Here is the PowerShell script to delete the empty folders under the Packages node(please replace the SiteCode and SiteServerName with yours):

 $ab = Get-WmiObject -Namespace “root\sms\site_xxx(SiteCode)” -ComputerName 'xxx(SiteServer)' -Query "SELECT * FROM SMS_ObjectContainerNode 
 where ObjectTypeName='sms_package'  and IsEmpty = 1 "
 $ab | remove-wmiobject


If the response is helpful, please click "Accept Answer"and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you so much. !237 empty folder in 11 seconds, not bad at all!

1 Vote 1 ·

What if the empty folder has a subfolder that is not empty? How do you delete only empty folders where there are no subfolders with items.

Thanks,

Jason

0 Votes 0 ·
canny avatar image canny JasonBromberg-8470 ·

A folder with a sub folder wouldn't be empty, it would have a folder in it so would be out of scope surely?

0 Votes 0 ·

The question was about what would happen if one of the sub folders wasn't empty (i.e. they had content in them and not just sub folders).
I've just run this and delete entire folder structures (it threw up errors, but worked) where all the folders AND subfolders were empty, and for the one folder that had sub folders that were NOT empty, the folder structure wasn't deleted. I deleted the content and ran the script again and he folder structure was now deleted.

0 Votes 0 ·