The script schedules delivery of a report for a user. The script should be executed in Windows PowerShell. When prompted, specify the credentials of the Adaxes service account.
The report will be delivered via email as an attachment in PDF format. For delivery, the report will be generated with its scope set to all managed domains (Everywhere) and will include the following columns: name, description, title. For details on specifying a scope and parameter values for report generation, see Generating reports.
Parameters:
- $serviceHost - Specifies the host name of the computer where Adaxes service is installed.
- $scheduledTaskDN - Specifies the distinguished name (DN) of the report scheduled task. For information on how to get the DN, see Get the DN of a directory object.
- $reportDN - Specifies the distinguished name (DN) of the report to schedule.
- $userDN - Specifies the distinguished name (DN) of the user to schedule the report for.
PowerShell
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
$serviceHost = "localhost" # TODO: modify me
$scheduledTaskDN = "CN=My Task,CN=Report Schedule,CN=Reports Root,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$reportDN = "CN=My Report,CN=Reports,CN=Reports Root,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$userDN = "CN=John Smith,OU=Users,DC=company,DC=com" # TODO: modify me
# Prompt for credentials.
$credential = Get-Credential
# Bind to the report and report scheduled task.
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly($serviceHost)
$scheduledTask = $admService.OpenObject("Adaxes://$scheduledTaskDN", $credential.UserName, $credential.GetNetworkCredential().Password, 0)
$report = $admService.OpenObject("Adaxes://$reportDN", $credential.UserName, $credential.GetNetworkCredential().Password, 0)
# Report data
$scheduledReportData = $scheduledTask.CreateReportData()
$scheduledReportData.Report = $report
# Arguments for report generation
$configuration = $report.GetConfiguration()
$arguments = $configuration.CreateReportArguments()
# Report scope
$scope = $configuration.CreateScope("ADM_REPORTSCOPETYPE_ADLOCATION")
$baseObject = $scope.CreateBaseObject()
$baseObject.ObjectReference = $NULL # Everywhere
$scope.BaseObjects = @($baseObject)
$arguments.Scope = $scope
# Parameter values
$arguments.SetParameterValue("param-textParameter", "MyValue")
$arguments.SetParameterValue("param-checkboxParameter", 1)
$scheduledReportData.ReportArguments = $arguments
# Document settings
$reportDocument = $scheduledReportData.CreateDocument("ADM_REPORTDOCUMENTTYPE_PDF")
$reportDocument.Content = "ADM_REPORTDOCUMENTCONTENT_TABLE"
$reportDocument.UseCustomColumnSettings = $True
$reportDocument.Columns.Columns = @("name", "description", "title")
$scheduledReportData.Document = $reportDocument
# Delivery options
$scheduledReportData.Delivery.EmailDelivery.Enabled = $True
$scheduledReportData.Delivery.EmailDelivery.AttachFile = $True
# Scheduled task item
$scheduledTaskItem = $scheduledTask.ScheduledReports.Create()
$scheduledTaskItem.ReportData = $scheduledReportData
$scheduledTaskItem.SetInfo()
# Specify recipient.
$user = $admService.OpenObject("Adaxes://$userDN", $credential.UserName, $credential.GetNetworkCredential().Password, 0)
$recipient = $scheduledTaskItem.ActivityScopeItems.Create()
$recipient.BaseObject = $user
$recipient.Exclude = $False
$recipient.Inheritance = "ADS_SCOPE_BASE"
$recipient.Type = "ADM_SCOPEBASEOBJECTTYPE_CONTAINER"
$recipient.SetInfo()
$scheduledTaskItem.ActivityScopeItems.Add($recipient)
# Schedule report.
$scheduledTask.ScheduledReports.Add($scheduledTaskItem)