I discovered that within a PowerShell (.ps1) script I can display the command line that launched the script with:
Write-Information $MyInvocation.Line -InformationAction Continue
However, when I pass variables on my command line, these variables are not expanded when displaying them with the command above.
I need them to be expanded for convenience purposes as I need anybody to be able to copy paste the command line without having the defined variables.
I tried something like:
# Display command
$fullCommand = $MyInvocation.MyCommand.Name
$MyInvocation.BoundParameters.Keys | ForEach {
$fullCommand += " -$($_) $($PSBoundParameters.Item($_))"
}
Write-Information $fullCommand -InformationAction Continue
This does not work as intended as the flags are not properly displayed.
A parameter block:
[CmdletBinding(DefaultParameterSetName="noUploadSet")]
param(
[switch] $SkipGetList,
[switch] $DisableHistory,
[string] $RefVersion,
[datetime] $ComputationDate,
[string] $RefEnv,
[string] $NewEnv,
[Parameter(Mandatory=$true)][string] $Perimeter,
[string] $ComputationType = "Test",
[string] $WorkingDir,
[string] $NewServiceName,
[Parameter(ParameterSetName="noUploadSet")][switch] $DebugMode,
[Parameter(ParameterSetName="uploadSet")][switch] $UploadNewService,
[string] $ScenarioPath,
[string] $User
)