Script repository
The script will export all the scripts from business rules, custom commands and scheduled tasks to TXT files named same as the scripts.
Parameters
$folderPath- the path to the folder where the scripts will be saved.$sendMail- set to$trueto send the scripts via email in attachments.$removeFiles- set to$trueto delete all the script files at the end of the script.$to- the address of the email notification recipient.$from- the email address from which the notification will be sent.$smtpServer- the SMTP server to use for sending the email notification.$subject- the email notification subject.$messageBody- the text of the email notification.
# File settings
$folderPath = "C:Scripts" # TODO: modify me
# Email 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
# A hash table with types of configuration objects and their aliases.
$configurationObjectInfos = @{
"BusinessRules" = "adm-BusinessRule";
"CustomCommands" = "adm-CustomCommand";
"ScheduledTasks" = "adm-ScheduledTask";
}
foreach ($alias in $configurationObjectInfos.Keys)
{
# Bind to the configuration container.
$configurationContainerPath = $Context.GetWellKnownContainerPath($alias)
$configurationContainer = $Context.BindToObject($configurationContainerPath)
# Find configuration objects.
$type = $configurationObjectInfos[$alias]
$configurationContainer.Criteria = New-AdmCriteria "$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 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}
}
Comments 8
You must be signed in to comment.
a_br
I'm trying to test this script in our environment. If I run it via PowerShell ISE on the Adaxes server I get a lot of errors (starts with line 24/25, can't call method on null-valued expression). Could you let me know the correct way to implement it?
Support
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.
Rubli Christian
HI,
if I run this Script I got this Message:
Illegales Zeichen im Pfad. Stapelüberwachung: bei , : Zeile 60
Have you any Idea?
Support
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.
Douglas
When I run this as using Adaxes cutom command, i do not get the output of the business rules; I only get custom commands. How do I fix this?
Support
Hello Douglas,
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.
DA
Can this be updated for the 2025 release? I get the following errors when I run it. This works on the 2023 release.
Cannot find an overload for "GetOperationName" and the argument count: "3". Stack trace: at GetActionsDescription, : line 44 ↲ at BuildActionConditionsDescription, : line 133 ↲ at BuildReport, : line 414 ↲ at , : line 588
Cannot find an overload for "GetOperationName" and the argument count: "3". Stack trace: at GetActionsDescription, : line 44 ↲ at BuildActionConditionsDescription, : line 133 ↲ at BuildReport, : line 414 ↲ at , : line 588
Cannot find an overload for "GetOperationName" and the argument count: "3". Stack trace: at GetActionsDescription, : line 44 ↲ at BuildActionConditionsDescription, : line 133 ↲ at BuildReport, : line 414 ↲ at , : line 588
Support
Hello,
As per our check, the script works fine. Are you sure this is the one you are actually using? If so, please, send us (support@adaxes.com) the script you are using in TXT format with all the modifications.