我为儿子写的剧本有问题。我的意图是简单地提醒他记住他的家务。我最近才开始做 PowerShell,我真的很喜欢它。我买了几本书,并浏览了许多其他帖子。
到目前为止,我所得到的如下所示,如果评估无法与-or
(或者我搞砸了?)
## REMINDERS TO DO CHORES ##
$sun = "Sunday"
$mon = "Monday"
$tue = "Tuesday"
$wed = "Wednesday"
$thu = "Thursday"
$fri = "Friday"
$sat = "Saturday"
$today = (get-date).DayOfWeek
$choreVac = "Vacuum the rooms and stairs"
$choreBath = "Clean the Bathroom Including emptying the garbage"
$choreOther = "No Chores Today -- But keep dishes done up"
if($today -eq $mon -or $wed -or $fri) {
msg /time:2500 * "Today is a Chore Day: your job is to $choreVac"
}
elseif ($today -eq $tue -or $sat ) {
msg /time:2500 * "Today is a Chore Day: your job is to $choreBath and PLEASE do a good job"
}
else {
msg /time:2500 * $choreOther
}
问题是我不认为它在当天被正确评估,所以今天是星期二,评估结果是$mon -or $wed -or $fri
如果我按如下方式每天重新编码,它会像预期的那样工作。为什么它不能与-or
?
if($today -eq $tue) {
msg /time:2500 * $choreBath
}