You’re right—there is no “Get-ActiveBatchSecuredVariable” cmdlet.
ActiveBatch doesn’t expose secured variables through a PowerShell-specific cmdlet; it simply injects them into the job at run time, and you pick them up the same way you would pick up any other variable inside PowerShell (or any other script type).
Below is the quick, canonical way to do it, followed by a deeper “why / how” explanation and some troubleshooting tips.
────────────────────────────────────────
-
Quick Recipe (works in >95 % of cases)
────────────────────────────────────────
-
In the Administration Console
Variables ► Secured Variables ► New
• Name: DB_Password
• Value:
• (optional) Scope / AES-256, etc.
-
In the job (or Plan) that will run the PowerShell:
Job ► Variables tab ► Add ► Secured Variable ► choose DB_Password
(make sure “Expose as Environment Variable” or the default variable creation
option is ticked—this is on by default in v11.x+).
-
Inside your PowerShell step / inline script:
# Grab the value that ActiveBatch injected
$plainTextPwd = $env:DB_Password
# If you need a SecureString to create a PSCredential:
$securePwd = ConvertTo-SecureString $plainTextPwd -AsPlainText -Force
$cred = New-Object pscredential("db_user", $securePwd)
Invoke-Sqlcmd -ServerInstance "SQL01" -Username $cred.UserName -Password $plainTextPwd `
-Query "EXEC dbo.DoWork"
• The value appears as plain text ONLY inside the process memory of the job.
• In the ActiveBatch log it shows as “****” or is redacted entirely.
That’s it—no special cmdlet required.
────────────────────────────────────────
2. What’s Happening Behind the Scenes
────────────────────────────────────────
• ActiveBatch stores the variable in its DB encrypted (AES or DES3 depending on how you set it up).
• When the job starts, the job scheduler decrypts the value in memory and:
– Substitutes the token in inline scripts (e.g. %%DB_Password%% or the
Insert-Variable token that looks like <%VAR 'DB_Password'%>), and/or
– Creates a temporary environment variable of the same name for the job’s
process tree (DB_Password=theDecryptedValue).
Both behaviours are on by default, but they can be toggled per-job.
• Because it’s just an environment variable, any scripting language running
inside that job can use it:
– PowerShell : $env:DB_Password
– CMD/Bat : %DB_Password%
– Python : os.environ['DB_Password']
• ActiveBatch masks the value anywhere it would normally hit disk (runtime
log, audit) unless you explicitly echo it yourself.
────────────────────────────────────────
3. Alternate Syntax (Token Replacement)
────────────────────────────────────────
If you prefer not to rely on the environment variable, you can use token
replacement directly inside the script field of the job step:
#Inline script example *inside* the Job definition UI
$pwd = "<%VAR 'DB_Password'%>" # ActiveBatch swaps this at run time
Write-Host "Password length is: $($pwd.Length)" # safe, shows only the length
Insert it via: right-click ► Insert Runtime Objects ► Variables ► Secured Variable.
────────────────────────────────────────
4. Common Pitfalls / Checklist
────────────────────────────────────────
☑ “Create Job Variables As Environment Variables” must be enabled
‑ Job ► Properties ► Execution ► Environment Variables (default = on).
☑ Variable names cannot contain spaces when referenced as $env:VAR_NAME.
☑ Never Write-Host or echo the raw value (unless you want it to leak).
☑ If you do echo it accidentally, ActiveBatch masks it in v11+, but older
versions (<10.0) need a patch.
☑ Using Inline credentials? Prefer $securePwd + pscredential so the clear
text doesn’t travel over the wire.
☑ If your script runs in a child process (e.g., you launch powershell.exe from
a CMD step), check “Inherit parent env. vars” so the variable is still there.
────────────────────────────────────────
5. Need to Fetch a Variable Dynamically (Advanced)?
────────────────────────────────────────
If you need to read a secured variable that is not attached to the job, you can:
a) Use the ActiveBatch REST API
b) Use ABATCommand.exe
ABATCommand.exe /VARIABLEGET:"DB_Password" /USER:"ABUser" /PASSWORD:"ABPwd"
(Obviously this only makes sense in special cases—tying the variable directly
to the job is almost always simpler and safer.)
────────────────────────────────────────
🎉 You’re set!
Use $env:<VariableName> (or token replacement) and let ActiveBatch do the
heavy lifting of decrypting, injecting, and masking the value for you.