Script repository

Run script in new PowerShell instance

Updated on: Jan 18, 2026, Views: 33437

Miscellaneous

The script executes the code from a business rule, custom command or scheduled task in a new PowerShell instance. The approach does not allow retrieving any data from the external instance.

Parameters

  • $waitTimeMilliseconds - the time during which Adaxes will wait for the script to complete. It is recommended not to set a time exceeding the 10 minutes limit applied by Adaxes to scripts executed by business rules, custom commands and scheduled tasks.
  • $scriptBlock - the PowerShell script that will be executed in the new PowerShell instance.
$waitTimeMilliseconds = 9 * 60 * 1000 # TODO: modify me

$scriptBlock = {
    Import-Module Adaxes

    $resource = 'https://api.example.com/users'
    $userDN = 'CN=John Doe,CN=Users,DC=example,DC=com'
    
    $user = Get-AdmUser -Identity $userDN -AdaxesService localhost | ConvertTo-Json
    Invoke-RestMethod -Method Post -Uri $resource -Body $user
} # TODO: modify me

# Start a new instance of Windows PowerShell and run the script.
$powershellPath = "$env:windir\system32\windowspowershell\v1.0\powershell.exe"
$process = Start-Process $powershellPath -NoNewWindow -ArgumentList ("-ExecutionPolicy Bypass -noninteractive -noprofile " + $scriptBlock) -PassThru
$process.WaitForExit($waitTimeMilliseconds)

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.