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 actions that do not execute the specified task runner
            if ($action.WorkingDirectory -NotMatch $application) {
                continue
            }

            # Find the executable
            $path = Join-Path $ReleaseDirectory -ChildPath $application | Join-Path -ChildPath $Version
            $exe = Get-ChildItem $path -Filter "*.exe" | Select -First 1

            # Update the action with the new working directory and executable
            $action.WorkingDirectory = $exe.DirectoryName
            $action.Path = $exe.FullName
        }
    }
}

지금까지 설명서에서 명백한 저장 기능을 찾을 수 없었습니다 ( https://msdn.microsoft.com/en-us/library/windows/desktop/aa383607(v=vs.85).aspx ). 여기에 잘못된 접근 방식을 취하고 있으며 작업 XML로 혼란스러워해야합니까?



답변

RegisterTask의 방법은 사용하는 것 업데이트 플래그를 가지고있다. 이 같은:

# Update the action with the new working directory and executable
$action.WorkingDirectory = $exe.DirectoryName
$action.Path = $exe.FullName

#Update Task
$taskFolder.RegisterTask($task.Name, $task.Definition, 4, "<username>", "<password>", 1, $null)

각 매개 변수에 대한 자세한 내용은 msdn 기사를 참조하십시오.


답변