Fraud Blocker Configure PowerShell Question Type - au2mator - Self Service Portal

Configure PowerShell Question Type

Last modified: August 29, 2023
You are here:
Estimated reading time: 1 min

Setting Information

  • Question Types
  • available since Release 4.4

Detailed Information

To configure PowerShell as a Question Type, configure your Service and choose “PowerShell” as a Type.

PowerShell Script

  • Choose a Script you want to execute. PowerShell Files need to be stored in your PowerShell Script Path.

Selection Type

  • Choose “Single” or “Multiple” Selection Type.

Something More

Since 4.5, you can transfer Values from the Service to the PowerShell Question Script to work with those Values.

We use the Built-In Initialize Data named “$au2matorhook” and transfer the result from the previous Question and the BuiltIn Data Parameters to this Parameter as JSON.

So, your first lines should be

param ($au2matorhook)
$jsondata = $au2matorhook | ConvertFrom-Json

And then $jsondata.**** has your Values stored.

So, for example, if you have a Question with the internal Name “CUser” you can get the Value with “$jsondata.CUser”

If you want to work with the Built-In Value, do it like this

$InitiatedBy=$jsondata.InitiatedBy

$Service=$jsondata.Service
$TargetUserId=$jsondata.TargetUserId

Return

Ensure your PowerShell Script returns a String so that the Value will be set in the Question as Answer.

If you return anything else, we try to show the result as a Prepoluated Table, and you can select the Values.

We recommend building a PSObject like the example below for an Array return.


$LicenseArray = @()
foreach ($R in $Result.value) {

    $DirPermissions = New-Object -TypeName PSObject
    $DirPermissions | Add-Member -MemberType NoteProperty -Name Name -Value $NiceName
    $DirPermissions | Add-Member -MemberType NoteProperty -Name License -Value $r.prepaidUnits.enabled
    $DirPermissions | Add-Member -MemberType NoteProperty -Name Used -Value $R.consumedUnits
    $DirPermissions | Add-Member -MemberType NoteProperty -Name Available -Value $Available
    $DirPermissions | Add-Member -MemberType NoteProperty -Name State -Value $State
    $LicenseArray += $DirPermissions
}

return $LicenseArray

Templates

See our GitHub Repo for our PS Templates:

https://github.com/au2mator/au2mator-PS-Templates

Was this article helpful?
Dislike 0