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 (160 points)

1 Answer

0 votes
by (211k 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.

Related questions

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 by ygini (160 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'm in the process of creating a Web interface for requesting IT accounts. Upon submission, I want to run a Powershell script that will create an item in a Sharepoint task list.

asked May 14 by sandramnc (730 points)
0 votes
1 answer

Hello, We're working with Adaxes for about 2 months and we can't seem to find out how we can check if a action in Adaxes worked or not. We have a ... action failed and react to it and is there something similiar to $ErrorActionPreference for adaxes actions?

asked Nov 14, 2019 by PGstoehl (100 points)
0 votes
0 answers

I have created a Custom action to create some "standard" sub OUs to a particular type of OU in our AD. I wanted to create a script to look in the OU you are executing ... 'Users') -or ($child.Name -eq 'Computer Systems')) {$Context.ConditionIsMet = $False } }

asked Aug 31, 2016 by ggallaway (300 points)
2,607 questions
2,344 answers
6,228 comments
861,030 users