Reputation: 1326
I have the following code:
Start-Job -ScriptBlock $Function:DbRefresh -argumentlist $DestSqlInstance , `
$RefreshDatabase , `
$PfaEndpoint , `
$PfaCredentials , `
$RefreshSource , `
$ForceDestDbOffline, `
$NoPsRemoting , `
$PromptForSnapshot , `
$ApplyDataMasks | Out-Null
The last four arguments are switches that are passed into the function this statement appears in, the position and type of the arguments that DbRefresh is called with are all correct. Despite this my job is aborting with:
A positional parameter cannot be found that accepts argument 'False'.
+ CategoryInfo : InvalidArgument: (:) [], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound
clearly there is some nuance to calling a function via Start-Job with switches that I've missed out. + PSComputerName : localhost
Upvotes: 1
Views: 242
Reputation: 94
You'll need to adapt this to your scenario, but this implementation should do what you need.
[scriptblock]$sb = {
function isOn {
param (
[switch]$on
)
if ($on) {write-output "on"} else { write-warning "off" }
}
isOn -On:$Args[0]
}
@($true,$false) | %{ start-job -ScriptBlock $sb -ArgumentList @($_) }
Get-Job |Receive-Job
on
WARNING: off
Upvotes: 2