The script generates a report and exports it to a file. The script should be executed in Windows PowerShell. When prompted, specify the credentials of the Adaxes service account.
The script generates a report with its default columns. For details on specifying arguments for report generation, see Generating reports.
Parameters:
- $serviceHost - Specifies the host name of the computer where Adaxes service is installed.
- $reportDN - Specifies the distinguished name (DN) of the report to export. For information on how to get the DN, see Get the DN of a directory object.
- $documentType - Specifies the type of the report document that will be created. For available document types, see ADM_REPORTDOCUMENTTYPE_ENUM.
- $documentContent - Specifies what will be included into the report document. For available content types, see ADM_REPORTDOCUMENTCONTENT_ENUM.
- $filePath - Specifies the path to the file that will be created.
PowerShell
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
$serviceHost = "localhost" # TODO: modify me
$reportDN = "CN=My Report,CN=Reports,CN=Reports Root,CN=Configuration Objects,"+
"CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$documentType = "ADM_REPORTDOCUMENTTYPE_PDF"
$documentContent = "ADM_REPORTDOCUMENTCONTENT_TABLE,
ADM_REPORTDOCUMENTCONTENT_GENERATIONDATE,
ADM_REPORTDOCUMENTCONTENT_REPORTDESCRIPTION,
ADM_REPORTDOCUMENTCONTENT_TOTALCOUNT" # TODO: modify me
$filePath = "C:\Reports\My Report.PDF" # TODO: modify me
# Prompt for credentials.
$credential = Get-Credential
# Bind to the report.
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly($serviceHost)
$report = $admService.OpenObject("Adaxes://$reportDN", $credential.UserName, $credential.GetNetworkCredential().Password, 0)
# Arguments for report generation
$configuration = $report.GetConfiguration()
$arguments = $configuration.CreateReportArguments()
$arguments.Columns = $configuration.Generator.Columns.Columns
# Generate the report.
$listItems = $report.Generate($arguments)
# Wait till all report items are fetched.
while (!$listItems.Completed)
{
Sleep -Milliseconds 100
}
# Bind to the 'Reports' container.
$reportsRootContainerPath = $admService.Backend.GetConfigurationContainerPath("ReportsRoot")
$reportsRootContainer = $admService.OpenObject($reportsRootContainerPath, $credential.UserName, $credential.GetNetworkCredential().Password, 0)
# Create report document.
$reportDocument = $reportsRootContainer.CreateDocument($documentType, $report)
$reportDocument.Content = $documentContent
$reportDocument.EnableObjectLinks = $True
# Save to file.
$bytes = $reportDocument.CreateDocument($NULL, $arguments, $listItems, $NULL)
Set-Content -Path $filePath -Value $bytes -Encoding Byte