Hi Guys,
Recently we started clearing all the collections in Configuration Manager which has zero members count then i started looking for WMI classes to achieve this task.Below are the two WMI classes i have used in my powershell script.
- SMS_Collection
- SMS_DeploymentSummary
below is the script which i have used to achieve this task.
<# .SYNOPSIS <A brief description of the script> .DESCRIPTION <A detailed description of the script> .PARAMETER <paramName> <Description of script parameter> .EXAMPLE <An example of using the script> #> # to retrieve the collection details which has ZERo member count and Zero Deployments associated for that collection. $ScriptPath = $MyInvocation.MyCommand.Path $ScriptDir = Split-Path -parent $ScriptPath Function Get-ColDetails { [cmdletbinding()] param( $SiteCode = '', $SiteServer= '' ) begin{} Process { $query = "select * from SMS_Collection where CollectionType='2' AND MemberCount = '0'" try{ $col = Get-WmiObject -Namespace "Root\SMS\Site_$($SiteCode)" -ComputerName $SiteServer -Query $query -ErrorAction Stop } catch { Write-Error $_.Exception.Message } $array = @() foreach ($colID in $col) { $depcount = Get-DeploymentCount -colID $colID.CollectionID -SiteCode $SiteCode -SiteServer $SiteServer $OutputObj = New-Object -Type PSObject $OutputObj | Add-Member -MemberType NoteProperty -Name CollectionID -Value $colID.CollectionID $OutputObj | Add-Member -MemberType NoteProperty -Name Name -Value $colID.Name $OutputObj | Add-Member -MemberType NoteProperty -Name LimitToCollectionID -Value $colID.LimitToCollectionID $OutputObj | Add-Member -MemberType NoteProperty -Name LimitToCollectionName -Value $colID.LimitToCollectionName $OutputObj | Add-Member -MemberType NoteProperty -Name MemberCount -Value $colID.MemberCount $OutputObj | Add-Member -MemberType NoteProperty -Name CollectionVariablesCount -Value $colID.CollectionVariablesCount $OutputObj | Add-Member -MemberType NoteProperty -Name ObjectPath -Value $colID.ObjectPath $OutputObj | Add-Member -MemberType NoteProperty -Name IsBuiltIn -Value $colID.IsBuiltIn $OutputObj | Add-Member -MemberType NoteProperty -Name TotalDepAssociated -Value $depcount $array+=$OutputObj } } end { if(Test-Path $ScriptDir\colinfo.csv -ErrorAction SilentlyContinue) { Write-Output "There is a previous Colinfo.csv file already exists, if you don't delete then content will be going to append to the Previous file" Remove-Item -Path $ScriptDir\colinfo.csv -ErrorAction SilentlyContinue -Confirm -Verbose } if($array) { $array | where {$_.IsBuiltIn -ne "True"} | Export-Csv $ScriptDir\colinfo.csv -NoTypeInformation -Append -Force -ErrorAction SilentlyContinue } } } Function Get-DeploymentCount([String]$colID,[String]$SiteCode,[string]$SiteServer) { $query = "select * from SMS_DeploymentSummary where CollectionID='$colID'" $depSum = Get-WmiObject -Namespace "Root\SMS\Site_$($SiteCode)" -ComputerName $SiteServer -Query $query return $depSum.Count }
Hope this helpful to you.
Please feel free to comment if you have any doubts . 🙂