Working with CIM sessions

As mentioned earlier in this chapter, a key feature of the CIM cmdlets is their ability to change how connections are formed and used.

The Get-CimInstance command has a ComputerName parameter, and when this is used, the command automatically creates a session to a remote system using WSMAN. The connection is destroyed as soon as the command completes.

While Get-CimInstance supports basic remote connections, it does not provide a means of authenticating a connection, nor can the protocol be changed.

The Get-CimSession, New-CimSession, New-CimSessionOption, and Remove-CimSession commands are optional commands that can be used to define the behavior of remote connections.

The New-CimSession command creates a connection to a remote server an example is as follows:

PS> $cimSession = New-CimSession -ComputerName Remote1
PS> $cimSession

Id : 1
Name : CimSession1
InstanceId : 1cc2a889-b649-418c-94a2-f24e033883b4
ComputerName : Remote1
Protocol : WSMAN

Alongside the other parameters, New-CimSession has a Credential parameter that can be used in conjunction with Get-Credential to authenticate a connection.

If the remote system does not, for any reason, present access to WSMAN, it is possible to switch the protocol down to DCOM by using the New-CimSessionOption command:

PS> $option = New-CimSessionOption -Protocol DCOM
PS> $cimSession = New-CimSession -ComputerName Remote1 –SessionOption $option
PS> $cimSession

Id : 2
Name : CimSession2
InstanceId : 62b2cb56-ec84-472c-a992-4bee59ee0618
ComputerName : Remote1
Protocol : DCOM

The New-CimSessionOption command is not limited to protocol switching; it can affect many of the other properties of the connection, as shown in the help and the examples for the command.

Once a session has been created, it exists in the memory until it is removed. The Get-CimSession command shows a list of connections that have been formed, and the Remove-CimSession command permanently removes connections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.48.62