How to do default parameter values in Powershell

February 6, 2022 ยท View on GitHub

You have to give a formal declaration of the function's parameter.

function Test {
	Param (
		[ValidateNotNullOrEmpty()]
		[String]
		$String = 'DEFAULT'
	)

	Write-Host -Object "String: $String"
}

See also

  • How to pass an argument to a powershell script