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
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
@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.
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
A folder with a sub folder wouldn't be empty, it would have a folder in it so would be out of scope surely?
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.
5 people are following this question.