背景:
阅读新闻

powershell task scheduler uncheck timezone

  作者: 今日评论: [字体: ]

    This solution works for me:

    # 1. Create your trigger as normal
    $trigger = New-ScheduledTaskTrigger -Daily -At 10:15am

    # 2. Then edit the trigger's StartBoundary property:
    $trigger.StartBoundary = [DateTime]::Parse(
        $trigger.StartBoundary).ToLocalTime().ToString("s")

    Explanation: When you create the trigger with New-ScheduledTaskTrigger, the time you specify is converted to UTC time and saved as a string in the trigger's StartBoundary property. On my machine, 10:15am produces a $trigger.StartBoundary of "2017-12-19T15:15:00Z", where the "Z" indicates UTC time. To specify a local time, we need to convert this date back into local time and remove the "Z"; we want "2017-12-19T10:15:00". The snippet above parses the date string, converts it to local time, and formats it in the correct format.

    This is really helpful when you are scheduling tasks to run as Group Managed Service Account because those tasks can only be set up through PowerShell!

    If you need to do this a lot you may find this function helpful:

    function Fix-Trigger {
        param( [parameter(ValueFromPipeline)] [CimInstance] $trigger )
        $newTrigger = $trigger.Clone()
        $newTrigger.StartBoundary = [DateTime]::Parse(
            $trigger.StartBoundary).ToLocalTime().ToString("s")
        $newTrigger
    }
    
    # Example usage:
    $trigger = New-ScheduledTaskTrigger -Daily -At 10:15am | Fix-Trigger
    来源:https://social.technet.microsoft.com/Forums/azure/en-US/e1dad780-6a99-44f2-9688-041e7026854b/quotsyn
    录入日期:[2019/06/05 17:14:00]
    收藏 推荐 打印 | 录入:mikebai | 阅读:
    文章评论      
    正在加载评论列表...
    评论关闭