October 2017
Intermediate to advanced
440 pages
11h 47m
English
The ArgumentList parameter of Invoke-Command does not offer a means of passing named arguments to a command.
Splatting allows parameters to be defined using a hashtable. Splatting uses the following format:
$params = @{
ID = $PID
}
Get-Process @params
The at symbol (@) is used to instruct PowerShell that the hashtable contains a set of parameters to a command.
The following example uses splatting to pass parameters. The function is defined on the local system, and the definition of the function is passed to the remote system:
# A function which exists on the current system function Get-FreeSpace { param ( [Parameter(Mandatory = $true)] [String]$Name ) [Math]::Round((Get-PSDrive $Name).Free / 1GB, 2) } # ...Read now
Unlock full access