Summary: Cloud & Datacenter Management MVP, Thomas Rayner, shows how to set a variable to a default value in PowerShell.
How can I use Windows PowerShell to prompt a user for a value for a variable, but provide a default value if the user doesn’t enter anything?
First prompt the user for the value to the variable and then detect if the response was empty. If the response is empty, set the value of the variable. You can validate parameters for a function more conveniently than this. This code is for inline variables in an interactive script:
$Interesting = Read-Host -Prompt ‘Give me a value [some-value]’
$Interesting = ‘some-value’