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://msexchange.me) 
#            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} 
} 
 
} 
 
####################################################################################

Regards

Sukhija Vikas

http://msexchange.me

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s