Home‎ > ‎Software‎ > ‎Microsoft‎ > ‎Exchange 2010‎ > ‎

Scheduled Scripts

Blah

Running script as a scheduled task

Important note from this article 
"If you have User Account Control (UAC) enabled, you may need to enable the option to Run with highest privileges "


Setting Task Priority

By default scheduled tasks have a priority of 7 "Low" you can not change this in the GUI 
  1. Export the Task to XML file
  2. Delete the Task
  3. Edit the XML file change priority from 7 to 6 "Normal"
  4. Import the XML file again to Task Scheduler



Script to migrate scheduled tasks from Windows XP/Server 2003 to 7/Server 2008

http://gallery.technet.microsoft.com/scriptcenter/Script-to-migrate-e4e5ea20


<# 
Usage: 
1. Run the script from the XP machine (in order to export the .job files, the schtasks commandline and the script itself) 
2. Run the script from the Windows 7 machine in order to copy the .job files, and run the XP schtasks command in order to "register" the files on the 7 machine 
#> 
 
#helper function 
function Browse-ForFolder($message){ 
    $shApp = New-Object -comObject Shell.Application 
    $folder = $shApp.BrowseForFolder(0,$message,0,0) 
    if ($folder -ne $null){ return $folder.self.path } 
} 
 
$isXP=(gwmi Win32_OperatingSystem).Version.StartsWith("5") 
 
if ($isXP){   
    $folder=Browse-ForFolder "Select the destination folder for the backup" 
    if ($folder -ne $null){ 
        #copy all the .jobs files,the xp schtasks commandline and the script itself 
        copy "$env:SystemRoot\Tasks\*" -filter "*.job" -recurse -dest $folder 
        copy "$env:SystemRoot\system32\schtasks.exe" -Destination $folder 
        copy "$env:SystemRoot\system32\schedsvc.dll" -Destination $folder 
        copy $MyInvocation.MyCommand.Path.ToString() -Destination $folder 
    } 
    exit 
} 
#on windows 7 machine 
else{ 
    $folder=Browse-ForFolder "Select the source folder of the backup" 
    if ($folder -ne $null){ 
        #copy all the .jobs files to the c:\windows\task folder on the destination machine 
        copy "$folder\*" -filter "*.job" -recurse -dest "$env:SystemRoot\Tasks" 
        $credential = Get-Credential 
        $pw=[Runtime.InteropServices.Marshal]::PtrToStringAuto(` 
            [Runtime.InteropServices.Marshal]::SecureStringToBSTR($credential.Password)) 
        $user=$credential.Username 
        # if non-domain credentials skip the backslash 
        if ($user.StartsWith("\")){ 
            $user=$credential.Username.Substring(1) 
        } 
        $tasks=gci $folder -Filter "*.job" 
        foreach ($task in $tasks){ 
            #run the xp schtasks command in order to register the tasks on the windows 7 machine 
            #skip .job postfix and add quotation-marks 
            $taskName="'" + $task.Name.substring(0,$task.Name.Length-4) + "'"  
            $allArgs = @("/change", "/TN", "$taskName","/RU" , "$user" , "/RP" ,"$pw" ) 
            & "$folder\schtasks.exe" $allArgs  
        } 
    } 
} 


Comments