February 2019
Intermediate to advanced
626 pages
15h 51m
English
The following example executes a function created on the local machine in a remote system using positional arguments:
function Get-FreeSpace {
param (
[Parameter(Mandatory = $true)]
[String]$Name
)
[Math]::Round((Get-PSDrive $Name).Free / 1GB, 2)
}
Invoke-Command ${function:Get-FreeSpace} -Session $session -ArgumentList C
This technique succeeds because the body of the function is declared as a script block. ArgumentList is used to pass a positional argument into the DriveLetter parameter.
If the function depends on other locally-defined functions, the attempt will fail.
Read now
Unlock full access