I would like the second function call in this script to throw an error:
function Deploy
{
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$BuildName
)
Write-Host "Build name is: $BuildName"
}
Deploy "Build123"
Deploy #Currently prompts for input
Prompting is great for using the script interactively, but this will also be executed by our build server.
Is my best bet just doing some custom validation with an if or something?
Once the parameter is marked as mandatory PowerShell will prompt for value. That said, if you remove the mandatory attribute then you can set a default value with a throw statement: