Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

New Post: Copy to Many

$
0
0

UPDATE: Your hint at the key work "clone" lead to another post where I found some sample code.

Posting my version here for future on lookers.

Thanks again.

 

    #Create a NetworkCredential to get the password
    $tmpNetworkCredential = $UserCredential.GetNetworkCredential();

    #Get TaskService
    $tmpTaskService = Get-TaskService -ComputerName $ComputerName -UserCredential $UserCredential;

    #Get New Empty ScheduledTask Definition
    $tmpNewTaskDefinition = $tmpTaskService.NewTask()

    #clone Triggers
    foreach ($tmpTrigger in $ScheduledTask.Definition.Triggers)
    {
        $tmpNewTaskDefinition.Triggers.Add($tmpTrigger.Clone());
    }

    #clone Actions
    foreach ($tmpAction in $ScheduledTask.Definition.Actions)
    {
        $tmpNewTaskDefinition.Actions.Add($tmpAction);
    }

    #clone Description
    $tmpNewTaskDefinition.RegistrationInfo.Description = $ScheduledTask.RegistrationInfo.Description;

    #Add cloned ScheduledTask
    $tmpTaskService.RootFolder.RegisterTaskDefinition($ScheduledTask.Name, $tmpNewTaskDefinition, 6, $UserCredential.Username, $tmpNetworkCredential.Password, 1, $null) #6 = Add or Update (2 = Add, 4 = Update), 1 = Supply Loggin Password, $null = sddl


Viewing all articles
Browse latest Browse all 2206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>