Hi team,

this script is with the new version not working anymore. Can you please update it? https://www.adaxes.com/script-repository/search-and-replace-text-in-adaxes-scripts-s224.htm

Cannot find an overload for "GetOperationName" and the argument count: "3".
At ADX - Search and replace text in Adaxes scripts.ps1:44 char:13
+             $actionDescription = $objectAction.GetOperationName("The  ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Unable to find type [Softerra.Adaxes.Utils.ObjectNameHelper].
At ADX - Search and replace text in Adaxes scripts.ps1:164 char:30
+ ... $objectDisplayName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObj ...
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Softerra.Adaxes.Utils.ObjectNameHelper:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound
by (2.2k points)
by (305k points)
0

Hello,

As pre our check, the script works just fine. How exactly did you execute it? Please, provide the exact command as well. Any additional details will be helpful.

by (2.2k points)
0

I am running it on Adaxes Server within Powershell ISE.

This is the script I am running

param(
    [Parameter(Mandatory=$true,Position=1)]
    [String]$textToSearch,
    [Parameter(Position=2)]
    [String]$replaceWith
)

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

# A hash table with types of configuration objects and their aliases
$configurationObjectInfos = @{
    "BusinessRules" = "adm-BusinessRule";
    "CustomCommands" = "adm-CustomCommand";
    "ScheduledTasks" = "adm-ScheduledTask";
}

function CheakActions ($actions, $textToSearch, $replaceWith, $objectType, $actionConditionList, $actionConditionCount)
{
    foreach ($action in $actions)
    {
        if ($action.Class -ne "adm-RunScriptAction")
        {
            continue
        }

        # Check whether the script contains the specified text
        $objectAction = $action.GetAction()
        $script = $objectAction.Script
        if (!($script.ToLower().Contains($textToSearch.ToLower())))
        {
            continue
        }

        # Get action description
        $actionDescription = $objectAction.CustomDescription
        if ([System.String]::IsNullOrEmpty($actionDescription))
        {
            $actionDescription = $objectAction.GetOperationName("The $objectType", $NULL, 
                "ADM_ACTIONNAMEFORMAT_SPECIFIC, 
                ADM_ACTIONNAMEFORMAT_CAPITALLETTER, 
                ADM_ACTIONNAMEFORMAT_PRESENTTENSE, 
                ADM_ACTIONNAMEFORMAT_SPECIFICINFOINADDITIONALDATA")
        }
        [void]$actionConditionList.AppendLine("`tAction: $actionDescription")

        $actionConditionCount.ActionCount++

        if ([System.String]::IsNullOrEmpty($replaceWith))
        {
            continue
        }

        # Update the action
        $script = $script.Replace($textToSearch, $replaceWith)
        $objectAction.Script = $script
        $action.SetAction($objectAction)
        $action.SetInfo()
    }
}

function CheckActionAndConditionSets($actionsAndConditionsSets, $textToSearch, $replaceWith, $objectType, $actionConditionList, $actionConditionCount, $isElseIfBlock)
{
    foreach ($actionsAndConditionsSet in $actionsAndConditionsSets)
    {
        # Check actions
        CheakActions $actionsAndConditionsSet.Actions $textToSearch $replaceWith $objectType $actionConditionList $actionConditionCount

        # Check conditions
        foreach ($condition in $actionsAndConditionsSet.Conditions)
        {
            if ($condition.Class -ne "adm-ScriptCondition")
            {
                continue
            }

            # Check whether the script contains the specified string
            $objectCondition = $condition.GetCondition()
            $script = $objectCondition.Script

            if (!($script.ToLower().Contains($textToSearch.ToLower())))
            {
                continue
            }

            # Get condition description
            $conditionDescription = $objectCondition.GetDescription($NULL)
            [void]$actionConditionList.AppendLine("`tCondition: $conditionDescription")

            $actionConditionCount.ConditionCount++

            if ([System.String]::IsNullOrEmpty($replaceWith))
            {
                continue
            }

            # Update Condition
            $script = $script.Replace($textToSearch, $replaceWith)
            $objectCondition.Script = $script
            $condition.SetCondition($objectCondition)
            $condition.SetInfo()
        }

        if ($isElseIfBlock)
        {
            continue
        }

        CheckActionAndConditionSets $actionsAndConditionsSet.ElseIfConditionedActions $textToSearch $replaceWith $objectType $actionConditionList $actionConditionCount $True

        if ($actionsAndConditionsSet.ElseActions.Count -ne 0)
        {
            CheakActions $actionsAndConditionsSet.ElseActions $textToSearch $replaceWith $objectType $actionConditionList $actionConditionCount
        }
    }
}

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

$totalActions = 0
$totalConditions = 0

foreach ($alias in $configurationObjectInfos.Keys)
{
    # Bind to the configuration container that contains objects of the current type
    $configurationContainerPath = $admService.Backend.GetConfigurationContainerPath($alias)
    $configurationContainer = $admService.OpenObject($configurationContainerPath, $NULL, $NULL, 0)

    # 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"

    $searcherResult = $configurationContainer.ExecuteSearch()
    $objects = $searcherResult.FetchAll()
    $searcherResult.Dispose()

    # Search scripts for the specified string
    foreach ($objectID in $objects)
    {
        # Bind to the Business Rule, Custom Command or Scheduled Task
        $object = $admService.OpenObject($objectID.AdsPath, $NULL, $NULL, 0)
        $actionConditionList = New-Object "System.Text.StringBuilder"

        # Perform search in scripts
        $actionConditionCount = @{ ActionCount = 0; ConditionCount = 0 }
        CheckActionAndConditionSets $object.ConditionedActions $textToSearch $replaceWith $object.ObjectType $actionConditionList $actionConditionCount $False

        if (($actionConditionCount.ActionCount -eq 0) -and ($actionConditionCount.ConditionCount -eq 0))
        {
            continue
        }

        # Output scripts found
        $objectDisplayName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($objectID.AdsPath, "IncludeParentPath")
        Write-Host "Object name: $objectDisplayName" 

        #Write-Host "Action/Condition description:"
        Write-Host $actionConditionList.ToString()

        if ($actionConditionCount.ActionCount -eq 0)
        {
            $totalConditions = $totalConditions + $actionConditionCount.ConditionCount
            #Write-Host "Search text found in" $actionConditionCount.ConditionCount "condition(s)"
            #Write-Host
        }
        elseif ($actionConditionCount.ConditionCount -eq 0)
        {
            $totalActions = $totalActions + $actionConditionCount.ActionCount
            #Write-Host "Search text found in" $actionConditionCount.ActionCount "action(s)"
            #Write-Host
        }
        else
        {
            $totalActions = $totalActions + $actionConditionCount.ActionCount
            Write-Host "Search text found in" $actionConditionCount.ActionCount "action(s)"

            $totalConditions = $totalConditions + $actionConditionCount.ConditionCount
            Write-Host "Search text found in" $actionConditionCount.ConditionCount "condition(s)"
            Write-Host
        }
    }
}

if ([System.String]::IsNullOrEmpty($replaceWith))
{
    Write-Host "Total actions found:" $totalActions
    Write-Host "Total conditions found:" $totalConditions
}
else
{
    Write-Host "Search text replaced in $totalActions actions."
    Write-Host "Search text replaced in $totalConditions conditions."
}

My console output

PS C:\Users\service-adaxes> \XX\Adaxes Server Scripts\ADX - Search and replace text in Adaxes scripts.ps1
cmdlet ADX - Search and replace text in Adaxes scripts.ps1 at command pipeline position 1
Supply values for the following parameters:
textToSearch: get-aduser
Cannot find an overload for "GetOperationName" and the argument count: "3".
At \XX\Adaxes Server Scripts\ADX - Search and replace text in Adaxes scripts.ps1:44 char:13
+             $actionDescription = $objectAction.GetOperationName("The  ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Unable to find type [Softerra.Adaxes.Utils.ObjectNameHelper].
At \XX\Adaxes Server Scripts\ADX - Search and replace text in Adaxes scripts.ps1:164 char:30
+ ... $objectDisplayName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObj ...
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Softerra.Adaxes.Utils.ObjectNameHelper:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Object name: 
    Action: 

Cannot find an overload for "GetOperationName" and the argument count: "3".
At \XX\Adaxes Server Scripts\ADX - Search and replace text in Adaxes scripts.ps1:44 char:13
+             $actionDescription = $objectAction.GetOperationName("The  ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Unable to find type [Softerra.Adaxes.Utils.ObjectNameHelper].
At \XX\Adaxes Server Scripts\ADX - Search and replace text in Adaxes scripts.ps1:164 char:30
+ ... $objectDisplayName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObj ...
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Softerra.Adaxes.Utils.ObjectNameHelper:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Object name: 
    Action: 

PS C:\Users\service-adaxes> 

1 Answer

by (305k points)
Best answer
0 votes

Hello,

Thank you for the provided details. We updated the script in the repository according to the changes introduced in Adaxes 2025.1. Sorry for the inconvenience.

by (2.2k points)
0

Thank you kindly. It is working now : )

Related questions

Just recently built a new server, installed 2025.1, and restored configuration from a backup of our other server running 2023.2. I updated the web interface address in ... d6d4f3bd7654 and I'm able to approve/deny from that interface without issue. Any ideas?

asked May 13 by msinger (230 points)
0 votes
1 answer

Ever since upgrading to 3.16.21906.0 the script here no longer works: https://www.adaxes.com/script-repository/move-mailbox-tofrom-microsoft-365-s579.htm Not sure what the issue is as I can't find any errors in the log.

asked Nov 16, 2023 by curtisa (350 points)
0 votes
0 answers

Hi all, We had patches installed on our Adaxes 2018.2, 2008 R2 server the other night. As part of that, Windows Management Framework ... -44db-b83c-3a0696611ddd/could-not-load-file-or-assembly-systemmanagementautomation-version3000?forum=virtualmachinemanager

asked Sep 26, 2019 by AllianceIT (130 points)
0 votes
0 answers

Hi, I have this Script to check if a condition is met # The condition is met if $Context.ConditionIsMet is set to $True. $Context.ConditionIsMet = $False $inputString = " ... or issue with this match function using in a "if script returns true" condition?

asked Oct 31, 2024 by wintec01 (2.2k points)
0 votes
1 answer

Hi All, I'm trying to use the powershell script provided here: https://www.adaxes.com/script-repository/move-mailbox-tofrom-microsoft-365-s579.htm Unfortuntately when executing ... credentials but I do not know why this error is happening. Thanks in advance

asked Aug 1, 2023 by curtisa (350 points)
0 votes
1 answer