Enable/ Disable Scheduled Tasks on Multiple Computers

Today, I am sharing a script that we have used to enable/ disable tasks on multiple servers.

This script had been utilized during the maintenance of these servers.

Download & extract script from below link, change the variables as per your environment

https://gallery.technet.microsoft.com/scriptcenter/Enable-Disable-Scheduled-7eb81379

$matching1 = “snapshot”

$matching2 = “Ent”

Update the servers.txt file to include the servers for which you will disable/Enable the tasks.

 

Now you can use the script as :

settasksts.ps1 Disable

settasksts.ps1 Enable

Another option is to run the batch file & it will prompt you for the input

Enter Enable for enabling the tasks that match Ent or snapshot in the Name

or enter Disable for disabling the tasks that matches Ent or snapshot

################################################################################### 
#            Author: Vikas Sukhija (http://techwizard.cloud) 
#            Date: 11/12/2015 
#            Update: 
#            Reviewer: 
#            Description: Enable/Disable Tasks 
################################################################################### 
 
param( 
     
$status 
 
) 
 
$matching1 = "snapshot" 
$matching2 = "Ent" 
 
write-host "After updating the servers file" -foregroundcolor Magenta 
write-host "Use Script as settasksts.ps1 status" -foregroundcolor Magenta 
write-host "-----------------------------------------------" -foregroundcolor Magenta 
write-host "--------Examples--------" -foregroundcolor Magenta 
write-host "Use Script as settasksts.ps1 Disable " -foregroundcolor Magenta 
write-host "Use Script as settasksts.ps1 Enable " -foregroundcolor Magenta 
 
write-host "You can also enter parameters when Prompted " -foregroundcolor Blue 
 
 
 
if($status -like $null){ 
 
$statusRead-host " Enter Value for Status: " } 
 
 
 
$servers = gc .\servers.txt 
 
 
$servers | foreach-object{ 
$srv = $_ 
        $schedule = new-object -com("Schedule.Service") 
        $schedule.connect("$srv") 
        $tasks = $schedule.getfolder("\").gettasks(0) 
        $totaltasks = $tasks | where{($_.Name -match $matching1-or ($_.Name -match $matching2)} 
$totaltasks | foreach-object { 
if($status -eq "Disable"){$_.Enabled = $False 
Write-host "Disabled Task "$_.name" for server $srv" -foregroundcolor Yellow} 
 
if($status -eq "Enable"){$_.Enabled = $True 
Write-host "Enabled Task "$_.name" for server $srv" -foregroundcolor Green} 
} 
 
} 
 
####################################################################################

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

Advertisement

2 thoughts on “Enable/ Disable Scheduled Tasks on Multiple Computers

  1. The script it does not work and I’m getting this error below, do you have any suggestion??, I’m to trying to disable “System State Backup” from over 600 VMs. your help is really appreciated to make the task easier.

    thanks.

    The network path was not found. (Exception from HRESULT: 0x80070035)
    At C:\Mustafa\TaskSts\TaskSts\settasksts.ps1:41 char:3
    + $schedule.connect(“$srv”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (:) [], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException

    This operation is supported only when you are connected to the server. (Exception from HRESULT: 0x800704E3)
    At C:\Mustafa\TaskSts\TaskSts\settasksts.ps1:42 char:3
    + $tasks = $schedule.getfolder(“\”).gettasks(0)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s