Dumping WMI Instance Property Values for all Classes in a Namespace

This is a continuation of my Troubleshooting WMI Repository Bloat post. Once you have identified the namespace and/or class that contains the most instances, there may be a reason that you want to see the properties of each instance. The script below dumps out the properties of all classes in the namespace specified. It dumps them out in individual CSV files, one for each class in the namespace, in the directory that the script is run in - so be careful where you run this script. All you need to do is plug in the namespace you are interested in into the top variable in the script.

  1 $nameSpace = 'root\ccm\policy\machine\actualconfig'
 2 [hashtable]$allInstances = @{}
 3 
 4 function Get-ScriptDirectory
 5 {
 6   $Invocation = (Get-Variable MyInvocation -Scope 1).Value
 7   Split-Path $Invocation.MyCommand.Path
 8 }
 9 
10 $path = Get-ScriptDirectory
11 
12 $objects = Get-WmiObject -Namespace $nameSpace -List
13 foreach ($object in $objects)
14 {
15   $instances = Get-WmiObject -Namespace $nameSpace -Class $object.Name -ErrorAction SilentlyContinue
16   $instanceLine = "{0}({1})" -f $object.Name, $instances.count
17   $entryName = "{0}:{1}" -f $nameSpace, $object.Name
18   $allInstances.Add($entryName, $instances.Count)
19   $count += $instances.Count
20   $outputFile = $object.Name + ".csv"
21   $path = Join-Path(Get-ScriptDirectory) $outputFile
22   $instances | sort name | select-object | Export-CSV $path -NoTypeInformation
23 }
24 
25 #export total list to csv
26 $outputFile = 'ClassDump.csv'
27 $path = Join-Path (Get-ScriptDirectory) $outputFile
28 $allInstances.GetEnumerator() | sort value -Descending | Export-Csv $path -NoTypeInformation
29 Write-Host ""
30 Write-Host "SCCM Instances Found: "$count
31 Write-Host "Overall Instance Output File: $path" 

DumpWMIProperties.renametops1