【发布时间】:2015-08-19 00:29:45
【问题描述】:
我为儿子编写的脚本有问题。我的意图是简单地提醒他记住他的家务。我最近才开始做 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
}
【问题讨论】:
-
啊,我刚刚想通了。如果 ($today -eq $mon -or $today -eq $wed -or $today -eq $fri) { 它有效,我必须完全限定它
-
随时发布您的问题的答案,详细说明您找到的解决方案。
-
你不应该在上面的问题中提供答案 :) 我已经删除了那部分。
-
@dan-gph 谢谢丹,我还没有能力为你的 cmets 投票,但不用担心。我很感激。
标签: powershell windows-10 powershell-ise powershell-5.0