Not really a question, just a piece of code I found interesting, so I’m putting it here in Discussions if anybody else finds it interesting enough to discuss.
Jeffrey Snover blogged about Private scope recently:
and one of the Scripting Games produced some discussion about selecting the protocol for CIM Sessions. They met in my ISE this morning and produced this:
function Get-_CIMSession { [CmdletBinding()] Param ([Parameter(Mandatory=$true,ValueFromPipeline=$true)] [string[]]$Computername) Begin { $_UseDCOM = New-CimSessionOption -Protocol DCOM $Private:PSDefaultParameterValues = $PSDefaultParameterValues.Clone() $PSDefaultParameterValues['New-CIMSession:SessionOption'] = $_UseDCOM $PSDefaultParameterValues['Test-WSMan:ErrorAction'] = 'Stop' } Process { foreach ($Computer in $ComputerName) { Try {Test-WSMan $Computer | out-null $_CIM = &{New-CimSession -ComputerName $Computer}} Catch { $_CIM = New-CimSession -Computername $Computer } $_CIM } } }