February 2019
Intermediate to advanced
626 pages
15h 51m
English
Splatting may be used to avoid repetition when a parameter must be optionally passed on to a number of different commands. It is possible to splat more than one set of parameters.
In this example, the ComputerName and Credential parameters are used by two different commands:
# Parameters used to authenticate remote connections$remoteParams = @{ Credential = Get-Credential ComputerName = $env:COMPUTERNAME}# Parameters which are specific to Test-WSMan$testWSMan = @{ Authentication = 'Default' ErrorAction = 'SilentlyContinue'}# By default, do not pass any extra parameters to New-CimSession$newCimSession = @{}if (-not (Test-WSMan @testWSMan @remoteParams)) { # If WSMan fails, use DCOM (RPC over TCP) to connect $newCimSession.Add('SessionOption', ...Read now
Unlock full access