Enabling and disabling scheduled tasks

The following code sample shows how to enable and disable a scheduled task.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the scheduled task
$scheduledTasksPath = $service.Backend.GetConfigurationContainerPath(
    "ScheduledTasks")
$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $scheduledTasksPath
$myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( `
    "CN=My Task")
$myScheduledTask = $service.OpenObject($myScheduledTaskAdsPath, $null, $null, 0)

# Enable the scheduled task
$myScheduledTask.Disabled = $false
$myScheduledTask.SetInfo()

# Disable the scheduled task
$myScheduledTask.Disabled = $true
$myScheduledTask.SetInfo()

See also