Using argument or default values in PowerShell Script

Hi,

I want my PowerShell script to use five variable values that the user will enter but if there is no value provided by the user, than it should take the default values that I would provide for those variables at the beginning.
What is the best approach to do this?

Thank you

Should be able to add something like below at the top of your script.

    Param
(
	[string]$param1 = "some default value",
	[string]$param2 = "some default value",
	[string]$param3 = "some default value",
	[string]$param4 = "some default value",
	[string]$param4 = "some default value"
)

Yes, this is for setting up the default values. But firstly I need to check if the user enters values for these variables.
If it does, than we should use the values that the user has entered. If there are no values provided, than the default ones.

That’s exactly how the parameter binder works. David’s example is exactly what you described. If the user provides any of those individually, those values will be used… otherwise the default values will be used. You would be duplicating work already handled by powershell. Maybe this example will help illustrate.

Function Test-DefaultValue {
    Param (
        $a = 'a',
        $b = 'b',
        $c = 'c'
    )

    'a','b','c' | foreach {
        write-host The value of parameter $_ is (get-variable $_).value
    } 
}
Test-DefaultValue

When called without providing values as shown, the output is

The value of parameter a is a
The value of parameter b is b
The value of parameter c is c

If you provide 1 or all with values, they will be used instead

Test-DefaultValue -a 'powershell' -c 'org'

The value of parameter a is powershell
The value of parameter b is b
The value of parameter c is org