powershell实现智能跳过节假日(2023)运行对应命令

poi2023-04-04技术交流7434

公司有个需求,工作日打开电视,节假日不打开电视。

写了个powershell脚本来判断是否是节假日或调休,具体执行内容是其他同事写的,就不粘贴上来了。可以在最下方的ifelse内自己实现。

<# ------
周末
    调休 =>开机(1)
    不调休 =>不开机(0)
工作日
    放假 =>不开机(0)
    不放假 =>开机(1)
------ #>


if ((Get-Date).DayOfWeek -eq 'Saturday' -or (Get-Date).DayOfWeek -eq 'Sunday') {
    # 周末调休 =>开机(1),周末不调休 =>不开机(0)
    $value = (Get-Date).Month.ToString()+'.'+(Get-Date).Day.ToString()
    switch($value)
    {
        "1.28" {$i = 1}
        "1.29" {$i = 1}
        "4.23" {$i = 1}
        "5.6" {$i = 1}
        "6.25" {$i = 1}
        "10.7" {$i = 1}
        "10.8" {$i = 1}
        Default {$i = 0}
    }
} else{
    # 工作日放假 =>不开机(0),工作日不放假 =>开机(1)
    $value = (Get-Date).Month.ToString()+'.'+(Get-Date).Day.ToString()
    switch($value)
    {
        "1.1" {$i = 0}
        "1.2" {$i = 0}
        "1.21" {$i = 0}
        "1.22" {$i = 0}
        "1.23" {$i = 0}
        "1.24" {$i = 0}
        "1.25" {$i = 0}
        "1.26" {$i = 0}
        "1.27" {$i = 0}
        "4.5" {$i = 0}
        "4.29" {$i = 0}
        "4.30" {$i = 0}
        "5.1" {$i = 0}
        "5.2" {$i = 0}
        "5.3" {$i = 0}
        "6.22" {$i = 0}
        "6.23" {$i = 0}
        "6.24" {$i = 0}
        "9.29" {$i = 0}
        "9.30" {$i = 0}
        "10.1" {$i = 0}
        "10.2" {$i = 0}
        "10.3" {$i = 0}
        "10.4" {$i = 0}
        "10.5" {$i = 0}
        "10.6" {$i = 0}
        Default {$i = 1}
    }
}
if ($i -eq 1)
{
    echo "$value,开机"
}else
{
    echo "$value,不开机"
}