- Accounts represent your organization and define access to Ansys entitlements.
- Groups allow finer-grained control—for example for specific products, license pools, or features.
Microsoft Entra ID membership sync
The scripts in this guide synchronize the membership of a Microsoft Entra ID (formerly Azure Active Directory) security group to an Ansys ID Portal account or group. They let an organization drive Ansys product access from existing identity workflows in Entra ID, without maintaining the same membership separately in the Ansys ID Portal. Two scripts perform the same synchronization:- sync_entra_to_ansys.py — Python, runs on Linux or Windows
- sync_entra_to_ansys.ps1 — PowerShell, runs on Windows only
How synchronization works
The script performs a one-way sync from Entra ID to the Ansys ID Portal. At each run it:- Reads the current membership of the specified Entra ID security group via the Microsoft Graph API, using the primary email address (mail attribute) of each member as the identifier. Members without a primary email address set in Entra are skipped with a warning.
- Reads the current membership of the target Ansys account or group via the Ansys ID Portal API.
- Compares the two lists and computes the difference — which users need to be added and which need to be removed.
- Applies the changes to bring the Ansys target into exact alignment with the Entra group.
Sync to an Ansys ID Portal account
When —target-type account is specified, the script synchronizes the membership of an Ansys ID Portal account. An account represents a customer organization in the Ansys ID Portal and controls which users have access to that organization’s Ansys products and licenses. After a successful sync, the users with membership in the account will exactly match the members of the Entra group (subject to any preserved email addresses — see —preserve-email below). The account must already exist in the Ansys ID Portal. The script resolves the account name to its internal UUID automatically.Sync to a named group within an Ansys ID Portal account
When —target-type group is specified, the script synchronizes the membership of a named group within an Ansys ID Portal account. Groups within an account can be used to control access to specific Ansys products, license pools, or features at a finer granularity than the account itself. After a successful sync, the members of the named Ansys group will exactly match the members of the Entra group. If the named group does not yet exist in the Ansys ID Portal it will be created automatically as a General type group. Users added to the group are also automatically added to the account if they are not already members. The account under which the group resides must already exist.What the script does not do
- It does not create Ansys ID Portal accounts — they must pre-exist.
- It does not manage roles or permissions within an account or group, only membership.
- It does not sync in the reverse direction — changes made directly in the Ansys ID Portal will be overwritten on the next sync run.
- It does not manage nested Entra groups directly, but it does flatten them — members of nested groups are included via the Graph API transitiveMembers endpoint.
Prerequisites (all platforms)
Complete these steps once before running the script on any platform.Entra ID app registration
The script reads group membership from Entra ID using the Microsoft Graph API. This requires an app registration in your Entra tenant with appropriate permissions. Follow the full instructions in Entra ID app registration setup. You will need the following values from that process:- Entra ID tenant domain (e.g. contoso.onmicrosoft.com)
- App registration Client ID
- App registration Client Secret
Ansys ID Portal access
You will need:- The Ansys ID Portal account number for the account to sync into, or to sync a group within. The account must already exist.
- An Ansys Personal Access Token (PAT) belonging to a user who is a member of that account and holds an ASC or Customer Administrator role. The PAT is obtained from the Ansys ID Portal. It is a long string and it is not your Ansys account password. The user whose PAT is used must remain a member of the account — use —preserve-email to prevent them being removed during sync if they are not in the Entra group.
- If syncing to a named group: the name of the group (it will be created automatically if it does not exist).
Network access
The machine running the script must be able to reach:- https://login.microsoftonline.com (Entra ID token endpoint)
- https://graph.microsoft.com (Microsoft Graph API)
- https://ansysaccount.b2clogin.com (Ansys B2C authentication)
- https://iam.ansys.com (Ansys ID Portal API)
Usage examples
Sync an Entra group to an Ansys account (Python)
The following example synchronizes the Entra group “Ansys License Users” to an Ansys ID Portal account. After running, the account membership will exactly match the Entra group, except that svc-account@contoso.com will never be removed regardless of Entra group membership.Sync an Entra group to a named group within an Ansys account (Python)
The following example synchronizes the same Entra group to a named group called “Engineering Team” within the account. The group is created if it does not exist. Members added to the group are automatically added to the account as well.Same examples in PowerShell
Preview changes without applying them
Add —dry-run (Python) or -DryRun (PowerShell) to any command to log what would be added and removed without writing any changes:Python on Linux
Prerequisites
Most Linux distributions include Python 3 by default. Verify:Create a virtual environment
Modern Debian-based distributions (Ubuntu 23.04+, Linux Mint 22+) prevent pip from installing packages system-wide to protect the OS. A virtual environment is the correct solution and is good practice on all Linux distributions regardless.Install dependencies
With the virtual environment active:Place the script
Copy sync_entra_to_ansys.py to a convenient location:Run the script manually
Activate the virtual environment first if not already active:Token cache
The first time the script authenticates to Ansys it will prompt for your PAT and cache the resulting token in.token_cache.json in the directory
from which you run the script. On subsequent runs the cached token is
reused and refreshed silently without prompting for the PAT again.
For scheduled runs, run the script interactively once first to populate
the token cache, then schedule it.
Restrict permissions on the cache file:
Schedule with cron
For automated recurring sync, add a cron job. Because the virtual environment is not activated in cron, call the Python interpreter inside it directly. Open the cron editor:- The log directory must exist: mkdir -p ~/logs
- Cron runs with a minimal environment. Use full absolute paths throughout.
- The token cache file will be written to the home directory when run from cron. Use —log-file so you have a record of each run.
- Test the full command manually before scheduling it.
Log file
If you use —log-file, the directory must already exist:Python on Windows
Install Python
- Go to https://www.python.org/downloads/
- Click the large Download button (it auto-detects Windows).
- Run the installer. IMPORTANT: On the first screen, check “Add python.exe to PATH” before clicking Install Now. If you miss this, uninstall and reinstall.
- Click Close when done.
Install dependencies
In Command Prompt:Place the script
Copy sync_entra_to_ansys.py to a convenient folder, for example:Run the script manually
The ^ character is the Windows Command Prompt line-continuation character. See Usage examples above for full examples. Note: if your —entra-client-secret contains special characters such as ! % ^ & these may be misinterpreted by Command Prompt. If authentication fails, omit —entra-client-secret from the command and let the script prompt for it instead — the prompt bypasses Command Prompt’s parser. Alternatively use the PowerShell script which handles special characters correctly with single-quoted strings.Token cache
The first time the script authenticates to Ansys it will prompt for your PAT and cache the resulting token in.token_cache.json in the directory
from which you run the script. On subsequent runs the cached token is
reused and refreshed silently.
For scheduled runs, run the script interactively once first to populate
the token cache, then schedule it.
Schedule with Task Scheduler
- Press Win + R, type taskschd.msc, press Enter.
- Click Create Task (not Basic Task) in the right panel.
- General tab:
- Name: Ansys ID Portal Sync
- Select: Run whether user is logged on or not
- Check: Run with highest privileges
- Triggers tab > New:
- Set your desired schedule (e.g. Daily at 2:00 AM)
- Actions tab > New:
- Action: Start a program
- Program/script: (find your Python path — see below)
- Add arguments: (all script arguments on one line)
- Settings tab:
- Check: If the task is already running, do not start a new instance
- Click OK and enter the Windows password for the account running the task.
Using a batch file instead of Task Scheduler arguments
For readability, save the command in a .bat file:PowerShell on Windows
Prerequisites
PowerShell is built into Windows and requires no installation. The script requires PowerShell 5.1 or later, which is present on all supported versions of Windows 10 and Windows 11. Verify your version:Set execution policy
Windows prevents unsigned scripts from running by default. Allow locally created scripts to run (run this once in PowerShell as Administrator):Place the script
Copy sync_entra_to_ansys.ps1 to a convenient folder:Run the script manually
Open PowerShell (search for PowerShell in the Start menu). The backtick (`) is the PowerShell line-continuation character. Parameters use -Name ‘Value’ syntax with single quotes. See Usage examples above for full examples, including both account and group sync scenarios. Important: use single quotes (’) around values in PowerShell, not double quotes. Single quotes mean completely literal — no special character interpretation. This is particularly important for secrets that may contain characters like ! % ^ ~ & which have special meaning in double-quoted strings but are treated as plain text inside single quotes. If a value itself contains a single quote, escape it by doubling it: -EntraClientSecret ‘it”s-a-secret’Token cache
The first time the script authenticates to Ansys it will prompt for your PAT and cache the resulting token in.token_cache.json in the directory
from which you run the script. On subsequent runs the cached token is
reused and refreshed silently.
Note: The Python and PowerShell scripts each maintain their own token cache file. Although both files are named .token_cache.json, they use different cache formats and are managed independently. Each script must be run interactively once to populate its own cache before being scheduled.
Use a PowerShell script file for repeated runs
Rather than typing the full command each time, save it as a .ps1 file:Schedule with Task Scheduler
- Press Win + R, type taskschd.msc, press Enter.
- Click Create Task (not Basic Task) in the right panel.
- General tab:
- Name: Ansys ID Portal Sync
- Select: Run whether user is logged on or not
- Check: Run with highest privileges
- Triggers tab > New:
- Set your desired schedule (e.g. Daily at 2:00 AM)
- Actions tab > New:
- Action: Start a program
- Program/script: powershell
- Add arguments: -NonInteractive -ExecutionPolicy RemoteSigned -File “C:\Scripts\run_sync.ps1”
- Settings tab:
- Check: If the task is already running, do not start a new instance
- Click OK and enter the Windows password for the account running the task.
Log file
Create the log directory before the first run:Quick reference — parameter / argument names
The Python and PowerShell scripts accept the same logical parameters but with different naming conventions. Python uses —hyphenated-names and PowerShell uses -PascalCaseNames. Here is the same content converted into a clean Markdown table:Cache files
The following files are created in the directory where the script runs. This directory should be accessible only to the account running the script.
The Python and PowerShell token caches are not interchangeable. Each script maintains its own cache and must be run interactively at least once to populate it before being used in a scheduled context. Because the names are identical it is advised to run each script in a separate folder/directory to avoid the cache file from being overwritten. Alternatively the scripts can easily be adjusted to name the token cache file uniquely if you wish to run both he python and PowerShell scripts in the same folder/directory.