- Collection ID (WMI: CollectionID)
- Name (Name)
- Refresh Type (RefreshType)
- Refresh schedule (RefreshSchedule.DaySpan, RefreshSchedule.HourSpan)
- Number of members (MemberCount)
- Limiting Collection Name (LimitToCollectionName)
- Limiting Collection ID (LimitToCollectionID)
- Number of Membership Rules (CollectionRules.Count)
- Exact Membership Rules (CollectionRules.RuleName, CollectionRules.IncludeCollectionID, CollectionRules.ExcludeCollectionID, CollectionRules.ResourceID, CollectionRules.QueryExpression)
SCCMCollectionsInformationExport.ps1
# created by Michael Sedenkov January 10, 2014
# Script listing SCCM 2012 Collections and their properties
# CSV file, where are we are going to export
$OutPutFile = "c:\temp\Collections.csv"
# name of SCCM 2012 server where are we connecting
$SCCMServerName = "CM01"
# name of SCCM 2012 namespace, containing SCCM Site Name
$SCCMNameSpace = "root\sms\site_XXX"
write-Output "CollectionID;CollName;RefreshType;Days;Hours;MemberCount;LimitingCollection;LimitingCollectionID;NumberOfCollectionRules;RuleName1;Rule1;RuleName2;Rule2;RuleName3;Rule3;RuleName4;Rule4" | Out-File $OutPutFile
gwmi sms_collection -computer $SCCMServerName -namespace $SCCMNameSpace | foreach {
$Coll = [wmi] $_.__Path
$CollRulesString = ""
if ($Coll.CollectionRules.Count) {
# in case some collection rules are really defined
$CollRuleCount = $Coll.CollectionRules.Count
foreach ($CollRule in $Coll.CollectionRules) {
#write-host "Collection Rule Name: " $CollRule.RuleName
$CollRulesString = $CollRulesString + $CollRule.RuleName + "; "
if ($CollRule.IncludeCollectionID) {
#write-host "Included collection: " $CollRule.IncludeCollectionID
$CollRulesString = $CollRulesString + "IncludedCollID " + $CollRule.IncludeCollectionID + "; "
}
if ($CollRule.ExcludeCollectionID) {
#write-host "Excluded collection: " $CollRule.ExcludeCollectionID
$CollRulesString = $CollRulesString + "ExcludedCollID " + $CollRule.ExcludeCollectionID + "; "
}
if ($CollRule.ResourceID) {
#write-host "Direct membership: " $CollRule.ResourceID
$CollRulesString = $CollRulesString + "MachineID " + $CollRule.ResourceID + "; "
}
if ($CollRule.QueryExpression) {
#write-host "Collection query: " $CollRule.QueryExpression
$CollRulesString = $CollRulesString + "Query " + $CollRule.QueryExpression + "; "
}
}
}
# if no rules are present
else { $CollRuleCount = 0 }
# convert RefreshType values into descriptions
$CollRefreshT = ""
switch ($Coll.RefreshType) {
1 {$CollRefreshT = "Manual"}
2 {$CollRefreshT = "Schedule"}
4 {$CollRefreshT = "Incremental"}
6 {$CollRefreshT = "Schedule+Incremental"}
}
write-host $Coll.CollectionID "; " $Coll.Name "; " $CollRefreshT "; " $Coll.RefreshSchedule.DaySpan "; " $Coll.RefreshSchedule.HourSpan "; " $Coll.MemberCount "; " $Coll.LimitToCollectionName "; " $Coll.LimitToCollectionID "; " $CollRuleCount "; " $CollRulesString #$Coll.CollectionRules[0].RuleName
Write-Output "$($Coll.CollectionID);$($Coll.Name);$($CollRefreshT);$($Coll.RefreshSchedule.DaySpan);$($Coll.RefreshSchedule.HourSpan);$($Coll.MemberCount);$($Coll.LimitToCollectionName);$($Coll.LimitToCollectionID);$($CollRuleCount);$($CollRulesString)" | Out-File $OutPutFile -Append
}
No comments:
Post a Comment