Creating and Using PowerShell Scripts

Root > Secret Server
PowerShell scripts can be used in Secret Server to automate specific tasks.  A PowerShell script can be configured as a dependency of a Secret and run after the password is successfully changed on the Secret or as a Password Changer. For more information on configuring a password changer PowerShell script refer to this KB.

Creating a PowerShell Script

From the Administration Menu, click Scripts button on the Remote Password Changing page, then click the Create New button.  Enter the "Name", "Description", and "Script" in the dialog then click OK.  Using PowerShell scripts as dependencies requires that Remote Password Changing is turned on, so ensure that this is enabled on the Remote Password Changing page.

Scripts may contain debug lines to help you in testing the working of the script. Debug statements use the Write-Debug command.

Write-Debug "The users name is $Username"
An input box for specifying arguments will exist in places where the PowerShell scripts are used.  Argument values are specified on a single line separated by a space.  Values containing spaces should be enclosed in quotes.  Parameters to PowerShell scripts are referenced through the zero based Args array.  It is often beneficial to assign Args variables to other more meaningful variables.

Arguments:  "Welcome back,"  Joe
$greeting = $Args[0]
$name = $Args[1]
Write-Debug "$greeting $name"‚Äč
Output: Welcome back, Joe

In situations where the script should fail given a specific set of conditions, an exception should be explicitly thrown.  When an exception is thrown, the script will stop running and the failure will be logged in the System Log.  The script is considered to have successfully run if no errors or exceptions occur while processing.

if ($meetsCondition -eq $false)
    throw "Did not meet condition"

Add Feedback