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…).
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)?