Mixing DCOM and WSMan in WMI Queries

by Mar 4, 2013

Using the new CIM cmdlets in PowerShell v3, you can run remote WMI queries against multiple computers using multiple remoting protocols.

The sample code below gets WMI BIOS information from five remote machines. It uses DCOM for the old machines in $OldMachines and uses WSMan for new machines in $NewMachines. Get-CimInstance gets the BIOS information from all five machines (make sure you adjust the computer names in both lists so that they match real computers in your environment, and that you have admin privileges on all of these machines):

# list of machines with no WSMan capabilities/no PSv3
$OldMachines = 'pc_winxp', 'pc_win7', 'server_win2003'

# list of new machines with PSv3 in place:
$NewMachines = 'pc_win8', 'server_win2012'

$useDCOM = New-CimSessionOption -Protocol DCOM 
$useWSMan = New-CimSessionOption -Protocol WSMan

$Session = New-CimSession -ComputerName $OldMachines -SessionOption $useDCOM 
$Session += New-CimSession -ComputerName $NewMachines -SessionOption $useWSMan 

# get WMI info from all machines, using appropriate protocol:
Get-CimInstance -CimSession $Session -ClassName Win32_BIOS

Twitter This Tip! ReTweet this Tip!