How to prevent PowerShell from prompting on Mandatory parameter on CI

[Parameter(Mandatory=$true, HelpMessage="Number of the Stage. e.g. 0")]
Write-Host $stage
> mv .\ParamPike.ps1 .\ParamSpike.ps1
PS C:\Users\tsushi\Code\PowerShell> .\ParamSpike.ps1
cmdlet ParamSpike.ps1 at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)


Don’t need it. The king of powershell told me.

Execute the PowerShell without the parameter

Why I wrote it?

I search on the internet and disillusioned the workaround for example, $sourceVersion=$(throw “The sourceValueis mandatory, please provide a value. e.g. -sourceVersion 3.0.15417”) It works, however, I was wondering if there is better approach. For someone who is the same as me.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store