Defining the scope of activity for a scheduled task

The following code sample makes a scheduled task effective for all objects in all the domains managed by Adaxes.

[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)

$scopeItem = $myScheduledTask.ActivityScopeItems.Create()
$scopeItem.BaseObject = $null
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_ALL_DIRECTORY"
$scopeItem.Inheritance = "ADS_SCOPE_SUBTREE"
$scopeItem.Exclude = $false
$scopeItem.SetInfo()

$myScheduledTask.ActivityScopeItems.Add($scopeItem)

The following code sample makes a scheduled task effective for all objects in a specific domain.

[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)

$domain = "example.com"
$domainObj = $service.OpenObject("Adaxes://$domain", $null, $null, 0)

$scopeItem = $myScheduledTask.ActivityScopeItems.Create()
$scopeItem.BaseObject = $domainObj
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_CONTAINER"
$scopeItem.Inheritance = "ADS_SCOPE_SUBTREE"
$scopeItem.Exclude = $false
$scopeItem.SetInfo()

$myScheduledTask.ActivityScopeItems.Add($scopeItem)

The following code sample makes a scheduled task effective for all objects located in an organizational unit.

[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)

$ouDN = "OU=Sales,DC=example,DC=com"
$ou = $service.OpenObject("Adaxes://$ouDN", $null, $null, 0)

$scopeItem = $myScheduledTask.ActivityScopeItems.Create()
$scopeItem.BaseObject = $ou
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_CONTAINER"
$scopeItem.Inheritance = "ADS_SCOPE_SUBTREE"
$scopeItem.Exclude = $false
$scopeItem.SetInfo()

$myScheduledTask.ActivityScopeItems.Add($scopeItem)

The following code sample makes a scheduled task effective for all members of a specific group.

[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)

$groupDN = "CN=My Group,DC=example,DC=com"
$groupObj = $service.OpenObject("Adaxes://$groupDN", $null, $null, 0)

$scopeItem = $myScheduledTask.ActivityScopeItems.Create()
$scopeItem.BaseObject = $groupObj
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_GROUP"
$scopeItem.Inheritance = "ADS_SCOPE_SUBTREE"
$scopeItem.Exclude = $false
$scopeItem.SetInfo()

$myScheduledTask.ActivityScopeItems.Add($scopeItem)

The following code sample makes a scheduled task effective for all members of a specific business unit.

[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)

$businessUnitsPath = $service.Backend.GetConfigurationContainerPath( `
    "BusinessUnits")
$businessUnitsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $businessUnitsPath
$myBusinessUnitPath = $businessUnitsPathObj.CreateChildPath( `
    "CN=My BusinessUnit")

$businessUnitObj = $service.OpenObject($myBusinessUnitPath, $null, $null, 0)

$scopeItem = $myScheduledTask.ActivityScopeItems.Create()
$scopeItem.BaseObject = $businessUnitObj
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_BUSINESSUNIT"
$scopeItem.Inheritance = "ADS_SCOPE_SUBTREE"
$scopeItem.Exclude = $false
$scopeItem.SetInfo()

$myScheduledTask.ActivityScopeItems.Add($scopeItem)

The following code sample makes a scheduled task effective for a specific organizational unit, but not its child objects.

[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)

$ouDN = "OU=Sales,DC=example,DC=com"
$ou = $service.OpenObject("Adaxes://$ouDN", $null, $null, 0)

$scopeItem = $myScheduledTask.ActivityScopeItems.Create()
$scopeItem.BaseObject = $ouObj
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_CONTAINER"
$scopeItem.Inheritance = "ADS_SCOPE_BASE"
$scopeItem.Exclude = $false
$scopeItem.SetInfo()

$myScheduledTask.ActivityScopeItems.Add($scopeItem) 

The following code sample excludes a specific user from the activity scope of 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)

$userDN = "CN=John Smith,CN=Users,DC=company,DC=com"
$userObj = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

$scopeItem = $myScheduledTask.ActivityScopeItems.Create()
$scopeItem.BaseObject = $userObj
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_CONTAINER"
$scopeItem.Inheritance = "ADS_SCOPE_BASE"
$scopeItem.Exclude = $true
$scopeItem.SetInfo()

$myScheduledTask.ActivityScopeItems.Add($scopeItem)

See also