0 votes

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"
$ClientSecret = "1234"
$Tenant = "some.url.tld"
$Directory = "0000"

Add-Type -AssemblyName System.Web


$encodedSecret = [System.Web.HttpUtility]::UrlEncode($ClientSecret)

$authToken = Invoke-RestMethod -Uri "https://$Tenant/SAAS/auth/oauthtoken" -Method Post -ContentType 'application/x-www-form-urlencoded' -Body "grant_type=client_credentials&client_id=$ClientId&client_secret=$encodedSecret&scope=admin"

$access_token = $authToken.access_token
$token_type = $authToken.token_type

 $headers = @{
    "Authorization" = "$token_type $access_token"
}

Invoke-RestMethod -Uri "https://$Tenant/SAAS/jersey/manager/api/connectormanagement/directoryconfigurations/$Directory/sync/v2" -Method Post -Headers $headers -ContentType "application/vnd.vmware.horizon.manager.connector.management.directory.sync.trigger.v2+json" -Body '{"ignoreSafeguards":"true"}' 

This script works in PowerShell directly, and works when run in the Adaxes full script editor. But when I try to run the related action (manually or with a real event) if fail reading the first line, whatever the firstline is (comment, empty, variable…).

image.png

image.png

How can I solve this?

Side question: is there a way to create a business rule that catch all directory event (create, update, delete) for Users and Groups (instead of having to create 6 independent rules with each of them a copy of the script)?

by (240 points)

1 Answer

0 votes
by (270k points)

Hello,

This script works in PowerShell directly, and works when run in the Adaxes full script editor. But when I try to run the related action (manually or with a real event) if fail reading the first line

As per our check, the script works fine. Most probably, there is some unprintable character in the script which causes the issue. To remedy the issue, try copying the script to notepad and then back to the script editor.

is there a way to create a business rule that catch all directory event

Unfortunately, there is no possibility to create such a business rule.

0

As per our check, the script works fine. Most probably, there is some unprintable character in the script which causes the issue. To remedy the issue, try copying the script to notepad and then back to the script editor.

I've already tried that and it does not solve the issue.

The script works in:

  • PowerShell ISE
  • PowerShell directly
  • Adaxes Administration Console via the PowerShell Script Editor

But fail in:

  • Adaxes Administration Console via the Edit Action pannel
  • Adaxes when the action is run

Any ideas?

0

Hello,

We copied the script right from your post here in our Q&A and it worked fine either way. Please, try the following:

  1. Remove the current Run a program or PowerShell script action.
  2. Copy the script from here using the Copy code option.
  3. Create a new Run a program or PowerShell script action and paste the script into it.
  4. Check whether the issue persists.
0

I've tried on a new Custom Command. Same result, but I didn't found a "Copy Code" option. Where is it?

Here is the screen shot of what I did step by step.

  • Here I clic on the Edit button Capture d’écran 2021-09-29 à 19.42.08.png

  • Here on the Open button Capture d’écran 2021-09-29 à 19.42.16.png

  • Here I pick the PowerShell script I want Capture d’écran 2021-09-29 à 19.42.25.png

  • It load it correctly, then I clic on Run Capture d’écran 2021-09-29 à 19.42.33.png

  • I target a sample object to run the command Capture d’écran 2021-09-29 à 19.42.53.png

  • It works fine Capture d’écran 2021-09-29 à 19.43.06.png

  • I close the editor and come back to the action, click Run again Capture d’écran 2021-09-29 à 19.43.19.png

  • I select the same test object Capture d’écran 2021-09-29 à 19.43.26.png

  • And this time the script fail Capture d’écran 2021-09-29 à 19.43.31.png

0

Hello,

We meant the Copy code button below the script you posted here. image.png You can also try to rewrite the first line in the script manually after pasting the script into the editor.

0

So i had to fix the exact same issue today. What i did was copy and paste the script 1 line at a time and run the script with each new line eventually i found the line that was causing the problem and manually retyped it and it solved the issue for me.

Related questions

0 votes
1 answer

So I need to export a list of all user's Line URI's to a CSV file. Running Adaxes 2021 Version 3.14.18804.0 (64 bit) and Teams Powershell 4.1.0 ... a Microsoft 365 account } finally { # Close the connection and release resources Disconnect-MicrosoftTeams }

asked Aug 4, 2022 by TheLexicon (200 points)
0 votes
1 answer

Hello, I'm working on different custom script to integrate Adaxes with custom Cloud Services. The goal will be to trigger Third Part Services directory sync on a ... an external exe that will be replicated by Adaxes automatically accross all Adaxes instances?

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

I've adapted a RegEx to normalize phone numbers, source: http://www.regexplanet.com/cookbook/pho ... index.html. Import-Module Adaxes $identity = "%sAMAccountName%" $mobileNumber = ' ... 555-5555, adaxes returned +1+1 (888) 555-5555. Any guidance on this?

asked Dec 20, 2014 by polley (1.2k points)
0 votes
1 answer

I created a group Business Rule that triggers "After adding or removing a member from a group". On its Activity Scope I added a test group, and set it for "The group ... does not trigger. What should I do to make the BR detect this (admittedly rare) case?

asked Mar 16, 2023 by alex.vanderwoude (60 points)
0 votes
1 answer

When running a PowerShell script as an action in a custom command, you can set the script to run as a different account and then use the RunAs property in the ... Is there another way to get the Adaxes service account's credentials from within the script?

asked Mar 31, 2022 by KelseaIT (320 points)
3,326 questions
3,025 answers
7,724 comments
544,677 users