The script will export all the scripts from business rules, custom commands and scheduled tasks, and save them to TXT files named same as the scripts themselves. the files can be sent to a predefined e-mail address and then removed.
Parameters:
- $folderPath - Specifies the path to the folder where the scripts will be saved.
- $sendMail - Specifies whether to send the scripts via email in attachments.
- $removeFiles - Specifies whether to remove the TXT files.
- $to - Specifies the recipient e-mail address.
- $from - Specifies the e-mail address from which the message will be sent.
- $smtpServer - Specifies the SMTP Server to use for sending the report.
- $subject - Specifies the notification message subject.
- $messageBody - Specifies the text for the notification message body.
PowerShell
# A hash table with types of configuration objects and their aliases
$configurationObjectInfos = @{
"BusinessRules" = "adm-BusinessRule";
"CustomCommands" = "adm-CustomCommand";
"ScheduledTasks" = "adm-ScheduledTask";
}
# File settings
$folderPath = "C:\Scripts" # TODO: modify me
# E-mail settings
$sendMail = $True # TODO: modify me
$removeFiles = $True # TODO: modify me
$to = "recipient@domain.com" # TODO: modify me
$subject = "Adaxes scripts" # TODO: modify me
$message = "Adaxes scripts" # TODO: modify me
$from = "noreply@domain.com" # TODO: modify me
$smtpServer = "mail.domain.com" # TODO: modify me
foreach ($alias in $configurationObjectInfos.Keys)
{
# Bind to the configuration container that contains objects of the current type
$configurationContainerPath = $Context.GetWellKnownContainerPath($alias)
$configurationContainer = $Context.BindToObject($configurationContainerPath)
# Find configuration objects of the current type
$type = $configurationObjectInfos[$alias]
$configurationContainer.SearchFilter = "(objectCategory=$type)"
$configurationContainer.PageSize = 500
$configurationContainer.SearchScope = "ADS_SCOPE_SUBTREE"
$configurationContainer.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
try
{
$searchResultIterator = $configurationContainer.ExecuteSearch()
$searchResults = $searchResultIterator.FetchAll()
# Search scripts
foreach ($searchResult in $searchResults)
{
# Bind to the Business Rule, Custom Command or Scheduled Task
$object = $Context.BindToObject($searchResult.AdsPath)
# Search scripts
foreach ($actionsAndConditionsSet in $object.ConditionedActions)
{
foreach ($action in $actionsAndConditionsSet.Actions)
{
if ($action.Class -ne "adm-RunScriptAction")
{
continue
}
$objectAction = $action.GetAction()
$script = $objectAction.Script
# Save the script to a file
$fileName = $objectAction.ScriptDescription
$script | Out-File -FilePath "$folderPath\$fileName`.txt"
}
}
}
}
finally
{
# Release resources
if ($searchResultIterator){ $searchResultIterator.Dispose() }
}
}
# Send mail
$files = (Get-ChildItem -Path $folderPath) | %%{$_.FullName}
if ($sendMail)
{
Send-MailMessage -to $to -From $from -Subject $subject -SmtpServer $smtpServer -Body $message -Attachments $files
}
if ($removeFiles)
{
$files | %%{Remove-Item -Path $_ -Confirm:$False -Force}
}
Hello,
The script can be executed only in a Business Rule, Custom Command or Scheduled Task, not in Windows PowerShell. For example, you can create a Custom Command configured for Domain-DNS object type and then execute the command on a domain registered in Adaxes. The domain will not specify the scope of objects affected by the script and will only be used to execute it. The export criteria are specified in the script itself.
if I run this Script I got this Message:
Illegales Zeichen im Pfad. Stapelüberwachung: bei <ScriptBlock>, <Keine Datei>: Zeile 60
Have you any Idea?
Hello,
Please, make sure that the path specified in the $folderPath variable is valid and corresponds to an existing folder on the computer where Adaxes service is installed. Additionally, make sure that the path does not contain illegal and non-printable characters.
As per our check, the script works exactly as intended. Could you, please, send us (support@adaxes.com) the exact script you are using with all the modifications you made? If you face any error messages, please, send us screenshots.