I'm working on a PowerShell script that needs to know the day of the week. I've got this part down: `$DoWk = (get-date $searchDate).dayofweek` and that seems to work fine. But when I try to check if it's Monday using an `if` statement like this: `if ($DoWk -ne Monday)`, I get an error that says "You must provide a value expression following the '-ne' operator." Can anyone help me figure out what I'm doing wrong? Thanks!
3 Answers
Just to add, since `$DoWk` returns an enum, a more precise way would be to use: `if ($DoWk -ne [System.DayOfWeek]::Monday)`. That way it checks against the actual enum value, which is what you're dealing with here.
As others have mentioned, you definitely need quotes. Just remember that `DayOfWeek` gives you an enum, so comparing it to just 'Monday' without quotes won’t work at all.
It looks like you forgot to put quotes around 'Monday'. It should be `if ($DoWk -ne 'Monday')` to treat it as a string.

Exactly! Remember, using the enum directly is often cleaner than string comparisons. Good call!