• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Powershell switch parameter question

Jeff7181

Lifer
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?
 
Last edited:
Back
Top