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 (294k 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
0 answers

Hi All, I have setup an action to cancel all meetings in outlook when a user is leaving. We use Exchange online but I'm getting an error 'The operation is supported by Exchange online and Exchange versions starting from 2019' I cant see where you specify.

asked Sep 6 by DarrenFisk (60 points)
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
0 answers

We have followed your instructions to set up the password self service and we got it to work on windows 10 but the link does not show up on windows 11. is there something we can do to get the link to show up?

asked May 1 by rechevarria (40 points)
0 votes
1 answer

In a business rule, I'd like to pass Adaxes variables into a powershell script that I'll run. For example, pass %username% into the script so it can be used inside the script.

asked Sep 5 by P-Sysadmin (20 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)
3,588 questions
3,277 answers
8,303 comments
548,084 users