小编Dav*_*eny的帖子

如何使用 Powershell 禁用计划任务?

我有一个在 Windows Server 2008 R2 上运行的 Web 应用程序,它有大量的计划任务,负责处理所有后端工作。当我进行涉及数据库的软件部署时,我需要禁用所有计划任务。目前,我有一个很长的清单,我需要手动逐步完成,在执行过程中禁用每个计划任务 - 当然,这是使用 Powershell 实现自动化的成熟工作。

不幸的是,Powershell 文档似乎对如何禁用现有的计划任务(当然,在成功完成发布后重新启用它)的内容相当含糊。我可以获得就绪、正在运行或已禁用任务的列表,但接下来怎么办?

automation powershell scheduled-task windows-server-2008-r2

8
推荐指数
2
解决办法
3万
查看次数

如何使用 Powershell 修改现有计划任务?

我正在开发一些使用 Powershell 更新执行各种应用程序的现有计划任务的发布自动化脚本。在我的脚本中,我可以设置应用程序的路径和工作目录,但它似乎没有将更改保存回任务。

function CreateOrUpdateTaskRunner {
    param (
        [Parameter(Mandatory = $TRUE, Position = 1)][string]$PackageName,
        [Parameter(Mandatory = $TRUE, Position = 2)][Version]$Version,
        [Parameter(Mandatory = $TRUE, Position = 3)][string]$ReleaseDirectory
    )

    $taskScheduler = New-Object -ComObject Schedule.Service
    $taskScheduler.Connect("localhost")
    $taskFolder = $taskScheduler.GetFolder('\')

    foreach ($task in $taskFolder.GetTasks(0)) {

        # Check each action to see if it references the current package
        foreach ($action in $task.Definition.Actions) {

            # Ignore actions that do not execute code (e.g. send email, show message)
            if ($action.Type -ne 0) {
                continue
            }

            # Ignore …
Run Code Online (Sandbox Code Playgroud)

automation powershell scheduled-task windows-server-2008-r2

8
推荐指数
1
解决办法
4406
查看次数