Copy to Many

Jun 19, 2012 at 9:30 AM

Can some one give me an example on how to copy from one server to many? Is it possable?

I first created a power shell script on my local (Win7) and was able to deploy Scheduled tasks to many servers using the XML property. But this all hit a pretty solid wall when i tried the script in out 2003 preprod server. I then found your dll and gave it a try but could not find a way to simply copy / paste. I have 40 servers in Prod and Copy / Paste is going to be more of a pain then getting this script to work with both versions.

My last attempt was to Register the source's task definition into the target's root but all that did was update the source. I'm guessing there must be a full path somewhere but i don't know where nore how to change it.

Is there by chance a code snippit to transfer the data from one definition to another?

Jun 19, 2012 at 4:17 PM

Unfortunately, under Task Scheduler Library 1.0 (XP/2003 Server and prior), there is not a simple way to "clone" the task definition. My suggestion would be to use this library to create the tasks as it will work between the 1.0 and 2.0 versions of the native COM libraries and then just loop through your servers, setting the TaskService.TargetServer property to the new server and the following the same steps to create the task. After changing the TargetServer property, you can even query the TaskService instance to see which version of the library you've connected to if you want to take advantage of 2.0 features specifically.

Jun 19, 2012 at 4:26 PM

OK thanks.

Side note: I don't know if it's your settings, mine or the site's but the notification email comes back in font size 4.

Is that normal?

Jun 20, 2012 at 3:21 PM

I think this is from CodePlex. I get the same thing.

Jun 20, 2012 at 3:27 PM

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)

    #clone Actions
    foreach ($tmpAction in $ScheduledTask.Definition.Actions)

    #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

Jul 2, 2012 at 6:15 PM

Update, in source code version 78863 and soon in release 1.8.3, XML input and output are supported for V1 instances.