Get CimAssociatedInstance - PowerShell


Overview

Get-CimAssociatedInstance retrieves associated Common Information Model (CIM) instances based on specified association classes. It allows you to explore relationships between CIM objects within a Windows system.

Syntax

Get-CimAssociatedInstance [-ComputerName] <string[]> [-AssociationClass] <string> [-ResultClassName] <string> [-ResultRole] <string> [-QueryLanguage] <string> [-Query] <string> [[-InitializationScript] <ScriptBlock>] [-Credential] <PSCredential> [-Authentication] <string> [-Port] <uint16> [-KeyLength] <int32> [-ImpersonationLevel] <string> [-Locale] <CultureInfo> [-ThrottleLimit] <int32> [-ErrorAction] <ActionPreference> [-ErrorVariable] <string> [-WarningAction] <ActionPreference> [-WarningVariable] <string> [-Verbose] [-Debug] [-OutVariable] <string> [-OutBuffer] <int32> [-PipelineVariable] <string>

Options/Flags

  • -ComputerName: Specifies the remote computer name to connect to. Use this parameter to manage remote systems.
  • -AssociationClass: Filters the results by the specified association class. This parameter limits the search to specific relationships.
  • -ResultClassName: Specifies the class of the returned instances. Use this to target specific types of objects.
  • -ResultRole: Filters the results based on the role of the source instance in the association. Use this to refine the search by relationships.
  • -QueryLanguage: Selects the query language to use. By default, WQL is used, but you can specify CQL or Dmtf Cim Query for more advanced queries.
  • -Query: Executes a specific query against the WMI repository. Use this option to customize the search parameters.
  • -InitializationScript: Runs a script block before connecting to the remote system. This allows you to configure the session or set variables.
  • -Credential: Specifies the credentials to use for connecting to the remote system. Use this to access systems with restricted access.
  • -Authentication: Sets the authentication mechanism to use. Options include Default, Negotiate, Basic, Credssp, Digest, Kerberos, and Ntlm.
  • -Port: Specifies the port number to use for the WMI connection. By default, port 135 is used.
  • -KeyLength: Sets the length of the encryption key for CredSSP authentication. Use this to meet security requirements.
  • -ImpersonationLevel: Sets the impersonation level to use when connecting to the remote system. Options include Default, Anonymous, Identify, Impersonate, and Delegate.
  • -Locale: Sets the locale to use for the WMI connection. By default, the system locale is used.
  • -ThrottleLimit: Sets the maximum number of concurrent operations that can be performed. Use this to manage system resources.
  • -ErrorAction: Specifies the action to take when errors are encountered. Options include Continue, Stop, SilentlyContinue, and Ignore.
  • -ErrorVariable: Sets a variable to store the error records encountered during the operation.
  • -WarningAction: Specifies the action to take when warnings are encountered. Options include Continue, Stop, SilentlyContinue, and Ignore.
  • -WarningVariable: Sets a variable to store the warning records encountered during the operation.
  • -Verbose: Enables verbose output, providing detailed information about the operation.
  • -Debug: Enables debug output, showing internal details of the command execution.
  • -OutVariable: Sets a variable to store the output of the command.
  • -OutBuffer: Specifies the number of objects to store in the output buffer before writing to the pipeline.
  • -PipelineVariable: Sets a variable to store the output of the command as it is passed through the pipeline.

Examples

Example 1: Retrieve all associations related to a specific instance

Get-CimAssociatedInstance -ComputerName server1 -ResultClassName Win32_LogicalDisk -ResultRole Antecedent

Example 2: Search for instances using a WQL query

Get-CimAssociatedInstance -ComputerName server2 -Query "SELECT * FROM Win32_Process WHERE ProcessId > 1000"

Example 3: Filter results based on association class and role

Get-CimAssociatedInstance -AssociationClass Win32_ProcessStartup -ResultRole Dependent -ResultClassName Win32_Process

Common Issues

  • Access Denied: Ensure that the user account has sufficient permissions on both the local and remote systems to perform WMI operations.
  • Invalid Query: Check the syntax and formatting of the WQL query. Use the -Verbose parameter to see the actual query being executed.
  • Remote Connection Failure: Verify that the remote WMI service is running and that the firewall is not blocking connections.

Integration

Get-CimAssociatedInstance can be used in conjunction with other PowerShell commands to automate complex tasks. For example, it can be used to:

  • Identify relationships between system components: Retrieve associated instances to map dependencies and troubleshoot issues.
  • Enumerate connected devices: Use the Win32_PnPEntity class to discover and retrieve information about peripherals.
  • Audit security settings: Combine with the Win32_SecurityDescriptor class to analyze and modify security permissions.
  • Get-CimClass: Retrieves information about a specific CIM class.
  • Get-WmiObject: Retrieves a WMI object based on its path.
  • Invoke-WmiMethod: Calls a method on a WMI object.