- Aug 21, 2002
- 18,368
- 11
- 81
In a powershell script, is there a way to determine if a parameter was set by being passed in at the command line at run time? Basically I have a script that I'm running on a schedule and it sets a switch based on the current day of the week. Sometimes I run that script manually and I want to pass in the value of that switch (true or false) no matter what day of the week it is.
I thought I could use a simple If statement to basically say, "if the switch is null (not passed in at the command line) run this code block to determine the day of the week and set the switch accordingly, else if the switch is passed in at the command line just use that value and don't evaluate anything." However (in Powershell, at least), a switch cannot be null so if I pass in a $false at the command line, it evaluates anyway. I don't want it to evaluate using the day of the week if I pass in the parameter at the command like regardless of whether I pass in $true or $false.
Do I need two parameters for this? One to tell it I'm passing in the value, don't evaluate anything, and one for the actual value?
I thought I could use a simple If statement to basically say, "if the switch is null (not passed in at the command line) run this code block to determine the day of the week and set the switch accordingly, else if the switch is passed in at the command line just use that value and don't evaluate anything." However (in Powershell, at least), a switch cannot be null so if I pass in a $false at the command line, it evaluates anyway. I don't want it to evaluate using the day of the week if I pass in the parameter at the command like regardless of whether I pass in $true or $false.
Do I need two parameters for this? One to tell it I'm passing in the value, don't evaluate anything, and one for the actual value?
Last edited:
