0 votes

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 = "%adm-DescriptionOfOperationToApprove%"

$pattern1 = "^Create.*\(DOMAIN\.COM\\OU\\OU\\Object Creation\\Group Creation (Development|Portfolio|Domain)\).*$"
$pattern2 = "^Run PowerShell script 'Update group and owner group' for .*?\(DOMAIN\.COM\\OU\\OU\\Distribution Groups\\(Development teams|Domains|Portfolios)\).*$"

if ($inputString -match $pattern1) {
    $Context.ConditionIsMet = $True
}
elseif ($inputString -match $pattern2) {
    $Context.ConditionIsMet = $True
}
else {
}

image.png

However, the condition is never met, the Script is never matching the pattern. image.png

Running the same script directly in ISE, is working fine. I even saved the value of adm-DescriptionOfOperationToApprove into a file, and loaded it into my ISE script to use the exact same value ... working ...

Is there any syntax change to be considered or issue with this match function using in a "if script returns true" condition?

by (1.5k points)

1 Answer

0 votes
by (292k points)

Hello,

We cannot comment on why the script works in Windows PowerShell. The reason is that value references (%adm-DescriptionOfOperationToApprove% in this case) do not work in it and you had to manually populate the $inputString variable. At the same time, it is expected for the script to always fail in Adaxes as the operation descriptions never match the patterns. Here are examples of the values the %adm-DescriptionOfOperationToApprove% value reference can resolve into in your case:

Create 'My group (compaony.com\Groups)'  ↲ Group Name: 'My Group', Group Type: 'Global, Security' ↲ Group Name (pre-Windows 2000): 'mygroup' ↲

Run PowerShell script 'Run PowerShell script 'Update group and owner group' for My group (domain.com\Groups)'
0

Really strange ... as you can see, I added an else action to my business rule.

This is basically the same script/check as within the "if script returns true" condition.

During an test with updating group, the condition was not met, however the script shows matched pattern ... image.png

Script:

$inputString = "%adm-DescriptionOfOperationToApprove%"
$inputString = $inputString.Trim()

$inputString2 = $inputString.Split("`n")

$pattern1 = "^Create.*\XXX\\Group Creation (Development|Portfolio|Domain)\).*$"

$pattern2 = "^Run PowerShell script 'Update group and owner group' for .*?\XXX(Development teams|Domains|Portfolios)\).*$"

$Context.LogMessage("$inputString", "Information")
$Context.LogMessage("$inputString2", "Information")
$Context.LogMessage("$pattern1", "Information")
$Context.LogMessage("$pattern2", "Information")

if ($inputString -match $pattern1) {
    $output = "Matched pattern 1: Create Group Creation"
    $Context.LogMessage("$output", "Information")
}
elseif ($inputString -match $pattern2) {
    $output = "Matched pattern 2: Update Group and Owner Group"
    $Context.LogMessage("$output", "Information")
}
else {
    $output = "No match found"
    $Context.LogMessage("$output", "Information") 
}
0

Update:

This is working fine, but I would need one check for each pattern ...

image.png

0

Hello,

Actually, you can use Else If blocks instead. For details and examples, see section Else If and Else blocks of the following tutorial: https://www.adaxes.com/help/AutomateUserProvisioning/#else-if-and-else-blocks.

Related questions

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 (290 points)
0 votes
1 answer

I am trying to send a $context.logmessage from a condition script in a Scheduled Task but I get nothing in the log. Is this not possible? Morten A. Steien

asked Jul 20, 2020 by Morten A. Steien (300 points)
0 votes
1 answer

Hello I'm trying to run a custom PowerShell script to request a Workspace ONE Access Sync when I change something in our users or groups. Here is the script: $ClientId = "api ... of having to create 6 independent rules with each of them a copy of the script)?

asked Sep 25, 2021 by ygini (240 points)
0 votes
1 answer

For creating a computer object, we want to check if the entered CN is already used in our AD. And for that we want to use a powershell script. An other dot ... powershell script should be start before creating the computer object, right? Thanks for your help.

asked Jun 4 by KEME (80 points)
0 votes
1 answer

Is there a way to have a Scheduled Task with 4 different condition? I want to create a scheduled task start every Monday and the condition see: The next Saturday of the week ... of the week is the fifth of the month then no action Thanks in advance, Simone

asked Jan 18, 2022 by Simone.Vailati (430 points)
3,569 questions
3,259 answers
8,275 comments
547,939 users