Version: 1.0
Category: Input
Extended Category: Powershell
Action Package: Standard Actions
Description
Run a powershell .ps1 file and create session objects for the result. The powershell script must receive a parameter called $outputfile and write the output to that file in UTF8 encoding. The output to the file must be one or multiple PSObjects in list format. It is possible to send additional powershell parameters to the script.
Parameter |
Description |
Example |
PowerShell File Path |
File path to PowerShell.exe. Default: file path in Global Parameter POWERSHELL_PATH. It is mandatory to set either this parameter or the global parameter. |
C:\Windows\System32\Windows\PowerShell\v1.0\powershell.exe |
PS1 File Path |
[Mandatory] File path to PS1 file. |
C:\Powershell\MyScript.ps1 |
Argument |
Optional arguments to send to the file. Each argument must be separeted by |. Ex: -user|SESSION(uid) to send the powershell parameter ‘user’ with the value in session attribute ‘uid’. |
-manager|SESSION(uid)|-location|Stockholm |
Only Run Once (true/false) |
[Optional] If the powershell script should run once and not one time for each object in the session. If using SESSION() in arguments, the values from the first session object will be used when running only once. Default value=true. |
false |
Max Execution Time (secs) |
[Optional] The maximum number of seconds the script/command can run before being forced to terminate. Use 0 for unlimited time. Default value=0 (unlimited). |
30 |
Error Message Attribute |
[Optional] If the Powershell script returns any error, the message will be placed in this attribute. If no error, the attribute will be created with no value. Leave blank to not create any error message attribute. |
ps-error |
Replace Existing Session Objects (true/false) |
[Optional] If the session objects from Powershell should replace all the existing session objects (true) or if they should be added to the list of existing session objects (false). Default: true. |
false |
Use Cases
Example 1: Run script with no parameters
This action will run a script that do not take any parameters. It will therefor only need to run once, and the new session objects will be added to the list of session objects.
The powershell file path has been entered in global parameter POWERSHELL_PATH.
Parameter |
Value |
PowerShell File Path |
[BLANK] |
PS1 File Path |
C:\Powershell\GetAllUsernames.ps1 |
Argument |
[BLANK] |
Only Run Once (true/false) |
true |
Max Execution Time (secs) |
[BLANK] |
Error Message Attribute |
[BLANK] |
Replace Existing Session Objects (true/false) |
false |
The script GetAllUsernames.ps1:
[CmdletBinding()] Param( [Parameter(Mandatory=$True)] [string]$outputfile ) $obj = Get-ADUser -Filter * -SearchBase 'OU=IM,DC=company,DC=local' Out-File -FilePath $outputfile -Encoding UTF8 -InputObject ($obj | Format-List SamAccountName)
Example 2: Run script with parameters
This action will run a script that requires a parameter. It uses the value from a session attribute in the parameter value, so it has to run once for each session object.
The result will be that the current session objects will be replaced by the new objects from Powershell, containing the attributes givenname and sn.
Parameter |
Value |
PowerShell File Path |
C:\Windows\System32\Windows\PowerShell\v1.0\powershell.exe |
PS1 File Path |
C:\Powershell\GetUsersByLocation.ps1 |
Argument |
-location|SESSION(location) |
Only Run Once (true/false) |
false |
Max Execution Time (secs) |
[BLANK] |
Error Message Attribute |
ps-error |
Replace Existing Session Objects (true/false) |
[BLANK] |
The script GetUsersByLocation.ps1:
[CmdletBinding()] Param( [Parameter(Mandatory=$True)] [string]$location, [Parameter(Mandatory=$True)] [string]$outputfile ) $result=Get-ADUser -LDAPFilter '(l=$location)' $obj = New-Object PSObject -Property @{ givenname = $result.GivenName sn = $result.Surname } Out-File -FilePath $outputfile -Encoding UTF8 -InputObject ($obj | Format-List)
DISCLAIMER
Information provided in this document is for your information only. PhenixID makes no explicit or implied claims to the validity of this information. Any trademarks referenced in this document are the property of their respective owners.The origin of this information may be internal or external to PhenixID. PhenixID makes all reasonable efforts to verify this information.
PhenixID - support.phenixid.se