Skip to content

Defining the scope of activity for a Scheduled Task

The following code sample makes a Scheduled Task effective for all objects in all AD domains managed by Adaxes.

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

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

# Bind to 'My Task' Scheduled Task
$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath(
    "ScheduledTasks")
$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $scheduledTasksPath
$myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( `
    "CN=My Task")
$myScheduledTask = $admService.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 Active Directory domain.

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

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

# Bind to 'My Task' Scheduled Task
$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath(
    "ScheduledTasks")
$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $scheduledTasksPath
$myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( `
    "CN=My Task")
$myScheduledTask = $admService.OpenObject($myScheduledTaskAdsPath, $NULL, $NULL, 0)

$domain = "example.com"
$domainObj = $admService.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
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to 'My Task' Scheduled Task
$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath(
    "ScheduledTasks")
$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $scheduledTasksPath
$myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( `
    "CN=My Task")
$myScheduledTask = $admService.OpenObject($myScheduledTaskAdsPath, $NULL, $NULL, 0)

$ouDN = "OU=Sales,DC=example,DC=com"
$ou = $admService.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
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to 'My Task' Scheduled Task
$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath(
    "ScheduledTasks")
$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $scheduledTasksPath
$myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( `
    "CN=My Task")
$myScheduledTask = $admService.OpenObject($myScheduledTaskAdsPath, $NULL, $NULL, 0)

$groupDN = "CN=My Group,DC=example,DC=com"
$groupObj = $admService.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
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to 'My Task' Scheduled Task
$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath(
    "ScheduledTasks")
$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $scheduledTasksPath
$myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( `
    "CN=My Task")
$myScheduledTask = $admService.OpenObject($myScheduledTaskAdsPath, $NULL, $NULL, 0)

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

$businessUnitObj = $admService.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
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to 'My Task' Scheduled Task
$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath(
    "ScheduledTasks")
$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $scheduledTasksPath
$myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( `
    "CN=My Task")
$myScheduledTask = $admService.OpenObject($myScheduledTaskAdsPath, $NULL, $NULL, 0)

$ouDN = "OU=Sales,DC=example,DC=com"
$ou = $admService.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
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to 'My Task' Scheduled Task
$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath(
    "ScheduledTasks")
$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $scheduledTasksPath
$myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( `
    "CN=My Task")
$myScheduledTask = $admService.OpenObject($myScheduledTaskAdsPath, $NULL, $NULL, 0)

$userDN = "CN=John Smith,CN=Users,DC=company,DC=com"
$userObj = $admService.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