For launching scripts with Start-Job it is required to use the correct order of parameters within the array provided to -ArgumentList.
Consider this script:
# $script = c:\myScripts.ps1
Param (
[Parameter(Mandatory)]
[String]$ScriptName,
[Parameter(Mandatory)]
[String]$Path,
[Parameter(Mandatory)]
[String[]]$MailTo,
[String]$LogFolder = "\\$env:COMPUTERNAME\Log",
[String]$ScriptAdmin = '[email protected]'
)
We would like to know how it is possible to retrieve the default values set in $LogFolder and $ScriptAdmin?
My attempt where I can't seem to find it:
$scriptParameters = (Get-Command $script).Parameters.GetEnumerator() |
Where-Object { $psBuildInParameters -notContains $_.Key }
foreach ($p in $scriptParameters.GetEnumerator()) {
'Name: {0} Type: {1} Mandatory: {2} DefaultValue: x' -f $p.Value.Name, $p.Value.ParameterType, $p.Value.Attributes.Mandatory
}
If we have the default value we can use Start-Job more flexible in case we want to start a job with only the mandatory parameters and say $ScriptAdmini, but want to keep the value in $LogFolder and not blank it out with an empty string because we need to respect the order or the arguments.