Skip to content

Instantly share code, notes, and snippets.

@mattifestation
Last active September 16, 2017 06:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattifestation/a39ae342f8b41664720f to your computer and use it in GitHub Desktop.
Save mattifestation/a39ae342f8b41664720f to your computer and use it in GitHub Desktop.
Enumerates all association classes and the classes they link for a given WMI namespace
function Get-AssociatedClassRelationship {
param (
[String]
$Namespace = 'root/cimv2'
)
Get-CimClass -Namespace $Namespace | ? { $_.CimClassQualifiers['Association'] -and (-not $_.CimClassQualifiers['Abstract']) } | % {
$KeyQualifiers = @($_.CimClassProperties | ? { $_.Qualifiers['key'] })
if ($KeyQualifiers.Count -eq 2) {
$Properties = [Ordered] @{
AssociationClassName = $_.CimClassName
LinkedClassName1 = $KeyQualifiers[0].ReferenceClassName
LinkedClassName2 = $KeyQualifiers[1].ReferenceClassName
}
New-Object PSObject -Property $Properties
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment