Retrieve the CIM instances that are connected to a specific CIM instance by an association.
Syntax Get-CimAssociatedInstance [-InputObject] CimInstance [[-Association] String] [ [-ComputerName String[]] | -CimSession CimSession[] } [-KeyOnly] [-Namespace String][-OperationTimeoutSec UInt32] [-ResourceUri Uri] [-ResultClassName String] [CommonParameters] Key -Association String The name of the association class. If you do not specify this parameter, the cmdlet returns all existing association objects irrespective of their type. For example, if class A is associated with class B through two associations, AB1 and AB2, then this parameter can be used to specify the type of association, either AB1 or AB2. -CimSession CimSession[] Run the command using the specified CIM session. Enter a variable that contains the CIM session, or a command that creates or gets the CIM session, such as New-CimSession or Get-CimSession. For more, see about_CimSessions. -ComputerName String[] The name of the computer on which you want to run the CIM operation. You can specify a fully qualified domain name (FQDN) or a NetBIOS name. If you specify this parameter, the cmdlet creates a temporary session to the specified computer using the WsMan protocol. If you do not specify this parameter, the cmdlet performs the operation on the local computer using COM. If multiple operations are being performed on the same computer, connecting using a CIM session gives better performance. -InputObject CimInstance Specifies a CIM instance object to use as input. If you are already working with a CIM instance object, you can use this parameter to pass the CIM instance object in order to get the latest snapshot from the CIM server. When you pass a CIM instance object as an input, Get-CimInstance returns the object from server using a get CIM operation, instead of an enumerate or query operation. Using a get CIM operation is more efficient than retrieving all instances and then filtering them. If the CIM class does not implement the get operation, then specifying the InputObject parameter returns an error. -KeyOnly Indicates that only objects with key properties populated are returned. Specifying the KeyOnly parameter reduces the amount of data transferred over the network. Use the KeyOnly parameter to return only a small portion of the object, which can be used for other operations, such as the Set-CimInstance or Get-CimAssociatedInstance cmdlets. -Namespace String Specifies the namespace of CIM operation. The default namespace is root/cimv2. NOTE: You can use tab completion to browse the list of namespaces, because wps_2 gets a list of namespaces from the local WMI server to provide the list of namespaces. -OperationTimeoutSec UInt32 Specifies the amount of time that the cmdlet waits for a response from the computer. By default, the value of this parameter is 0, which means that the cmdlet uses the default timeout value for the server. If the OperationTimeoutSec parameter is set to a value less than the robust connection retry timeout of 3 minutes, network failures that last more than the value of the OperationTimeoutSec parameter are not recoverable, because the operation on the server times out before the client can reconnect. -ResourceUri Uri Specifies the resource uniform resource identifier (URI) of the resource class or instance. The URI is used to identify a specific type of resource, such as disks or processes, on a computer. A URI consists of a prefix and a path to a resource. For example: http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_LogicalDisk http://intel.com/wbem/wscim/1/amt-schema/1/AMT_GeneralSettings By default, if you do not specify this parameter, the DMTF standard resource URI http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/ is used and the class name is appended to it. -ResourceURI can only be used with CIM sessions created using the WSMan protocol, or when specifying the -ComputerName parameter, which creates a CIM session using WSMan. If you specify this parameter without specifying the ComputerName parameter, or if you specify a CIM session created using DCOM protocol, you will get an error, because the DCOM protocol does not support the -ResourceURI parameter. If both the -ResourceUri parameter and the -Filter parameter are specified, the -Filter parameter is ignored. -ResultClassName String The class name of the associated instances. A CIM instance can be associated with one or more CIM instances. All associated CIM instances are returned if you do not specify the result class name. By default, the value of this parameter is null, which means all associated CIM instances will be returned. You can filter the association results to match a specific class name. Filtering happens on the server. If this parameter is not specified, Get-CIMAssociatedInstance returns all existing associations. For example, if class A is associated with classes B, C and D, then this parameter can be used to restrict the output to a specific type (B, C or D). CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer, PipelineVariable -OutVariable.
Get-CimAssociatedInstance retrieves the CIM instances connected to a specific CIM instance, called the source instance, by an association. In an association, each CIM instance has a named role and the same CIM instance can participate in an association in different roles.
If the -InputObject parameter is not specified, the cmdlet works in one of the following ways:
Standard Alias for Get-CimAssociatedInstance: gcai
Examples
Get the instances of the Win32_LogicalDisk class and store in a variable $disks.
Then get all the associated CIM instances of 'Logical Disk' via the first logical disk instance in $disk :
PS C:\> $disks = Get-CimInstance -ClassName Win32_LogicalDisk -KeyOnly
PS C:\> Get-CimAssociatedInstance -InputObject $disks[1]
Get the instances of the Win32_LogicalDisk class and store in a variable $disks.
Then get all the associated instances that are associated through the association class Win32_DiskPartition :
PS C:\> $disks = Get-CimInstance -ClassName Win32_LogicalDisk -KeyOnly
PS C:\> Get-CimAssociatedInstance -InputObject $disks[1] -ResultClass Win32_DiskPartition
Retrieve all the WMI services:
PS C:\> $services = Get-CimInstance -Query "Select * from Win32_Service where name like ꞌWinmgmtꞌ"
List the 'association' class names:
PS C:\> $classes = Get-CimClass -ClassName *Service* -Qualifier "Association"
PS C:\> $classes.CimClasName
Win32_LoadOrderGroupServiceDependencies
Win32_DependentService
Win32_SystemServices
Win32_LoadOrderGroupServiceMembers
Win32_ServiceSpecificationService
Get all the associated instances of the retrieved association class (Win32_DependentService):
PS C:\> Get-CimAssociatedInstance -InputObject $services -Association Win32_DependentService
“Always be yourself, express yourself, have faith in yourself, do not go out and look for a successful personality and try to duplicate it” ~ Bruce LeeRelated PowerShell Cmdlets:
Invoke-CimMethod - Invoke a method of a CIM class or CIM instance.
Get-CIMInstance - Get a managed resource (storage, network, software etc)
New-CimInstance - Create a new instance of a class.