Get-CimAssociatedInstance

Retrieves the CIM instances that are connected to a specific CIM instance by an association.

Syntax

Get-CimAssociatedInstance
   [[-Association] <String>]
   [-ResultClassName <String>]
   [-InputObject] <CimInstance>
   [-Namespace <String>]
   [-OperationTimeoutSec <UInt32>]
   [-ResourceUri <Uri>]
   [-ComputerName <String[]>]
   [-KeyOnly]
   [<CommonParameters>]
Get-CimAssociatedInstance
   [[-Association] <String>]
   [-ResultClassName <String>]
   [-InputObject] <CimInstance>
   [-Namespace <String>]
   [-OperationTimeoutSec <UInt32>]
   [-ResourceUri <Uri>]
   -CimSession <CimSession[]>
   [-KeyOnly]
   [<CommonParameters>]

Description

The Get-CimAssociatedInstance cmdlet 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 isn't specified, the cmdlet works in one of the following ways:

  • If neither the ComputerName parameter nor the CimSession parameter is specified, then this cmdlet works on local Windows Management Instrumentation (WMI) using a Component Object Model (COM) session.
  • If either the ComputerName parameter or the CimSession parameter is specified, then this cmdlet works against the CIM server specified by either the ComputerName parameter or the CimSession parameter.

Examples

Example 1: Get all the associated instances of a specific instance

$disk = Get-CimInstance -ClassName Win32_LogicalDisk -KeyOnly
Get-CimAssociatedInstance -InputObject $disk[1]

This set of commands retrieves the instances of the class named Win32_LogicalDisk and stores the information in a variable named $disk using the Get-CimInstance cmdlet. The first logical disk instance in the variable is then used as the input object for the Get-CimAssociatedInstance cmdlet to get all the associated CIM instances of the specified CIM instance.

Example 2: Get all the associated instances of a specific type

$disk = Get-CimInstance -ClassName Win32_LogicalDisk -KeyOnly
Get-CimAssociatedInstance -InputObject $disk[1] -ResultClass Win32_DiskPartition

This set of commands retrieves all the instances of the Win32_LogicalDisk class and stores them in a variable named $disk. The first logical disk instance in the variable is then used as the input object for the Get-CimAssociatedInstance cmdlet to get all the associated instances that are associated through the specified association class Win32_DiskPartition.

Example 3: Get all the associated instances through qualifier of a specific class

This set of commands retrieves the services that depend on the Winmgmt service and stores them in a variable named $s. Get-CimAssociatedInstance gets the associated instances of the retrieved association class.

$s = Get-CimInstance -Query "Select * from Win32_Service where name like 'Winmgmt'"
Get-CimAssociatedInstance -InputObject $s -Association Win32_DependentService

ProcessId Name            StartMode State   Status ExitCode
--------- ----            --------- -----   ------ --------
1716      RpcSs           Auto      Running OK     0
9964      CcmExec         Auto      Running OK     0
0         HgClientService Manual    Stopped OK     1077
0         smstsmgr        Manual    Stopped OK     1077
3396      vmms            Auto      Running OK     0

Parameters

-Association

Specifies the name of the association class. If you don't specify this parameter, the cmdlet returns all existing association objects of any 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.

Type:String
Position:1
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-CimSession

Runs 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 information, see about_CimSession.

Type:CimSession[]
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-ComputerName

Specifies 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 don't specify this parameter, the cmdlet performs the operation on the local computer using Component Object Model (COM).

If multiple operations are being performed on the same computer, connecting using a CIM session gives better performance.

Type:String[]
Aliases:CN, ServerName
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InputObject

Specifies the input to this cmdlet. You can use this parameter, or you can pipe the input to this cmdlet.

The InputObject parameter doesn't enumerate over collections. If a collection is passed, an error is thrown. When working with collections, pipe the input to enumerate the values.

Type:CimInstance
Aliases:CimInstance
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-KeyOnly

Returns objects with only key properties populated. This reduces the amount of data that's transferred over the network.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Namespace

Specifies the namespace for the CIM operation. The default namespace is root/cimv2.

Note

You can use tab completion to browse the list of namespaces, because PowerShell gets a list of namespaces from the local WMI server to provide the list of namespaces.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-OperationTimeoutSec

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 aren't recoverable, because the operation on the server times out before the client can reconnect.

Type:UInt32
Aliases:OT
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-ResourceUri

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 don't 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 get an error, because the DCOM protocol doesn't support the ResourceURI parameter.

If both the ResourceUri parameter and the Filter parameter are specified, the Filter parameter is ignored.

Type:Uri
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ResultClassName

Specifies 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 don't specify the result class name.

By default, the value of this parameter is null, and all associated CIM instances are returned.

You can filter the association results to match a specific class name. Filtering happens on the server. If this parameter isn't 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).

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

You can't pipe objects to this cmdlet.

Outputs

CimInstance

This cmdlet returns a CIM instance object.

Notes

Windows PowerShell includes the following aliases for Get-CimAssociatedInstance:

  • gcai