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.

Script repository

Export approval requests to CSV

March 17, 2021 Views: 2546

The script exports approval request information to a CSV file once an approval request is approved, denied or cancelled. To use it with Adaxes, create a business rule triggered after updating an approval request that runs the script.

Parameter:

  • $csvFilePath - specifies the path to the CSV file that will store information on approval requests.

Edit Remove
PowerShell
$csvFilePath = "\\Server\share\ApprovalRequests.csv" # TODO: modify me

# Build a new row for the CSV file
switch ($Context.TargetObject.ApprovalState)
{
    "ADM_APPROVALSTATE_PENDING"
    {
        return
    }
    "ADM_APPROVALSTATE_APPROVED"
    {
        $state = "Approved"
    }
    "ADM_APPROVALSTATE_DENIED"
    {
        $state = "Denied"
    }
    "ADM_APPROVALSTATE_CANCELED"
    {
        $state = "Canceled"
    }
}

$reportEntry = New-Object PSObject
$reportEntry | Add-Member -Name "State" -Value $state -MemberType NoteProperty
$reportEntry | Add-Member -Name "Requestor" -Value $Context.TargetObject.Requestor.Get("name") -MemberType NoteProperty
$reportEntry | Add-Member -Name "Processed By" -Value $Context.TargetObject.ProcessedBy.Get("name") -MemberType NoteProperty
$reportEntry | Add-Member -Name "Creation Date" -Value $Context.TargetObject.CreationDate -MemberType NoteProperty
$reportEntry | Add-Member -Name "Target Object" -Value $Context.TargetObject.TargetObject.Get("name") -MemberType NoteProperty

if ($state -ne "Approved")
{
    $denialOrCancelingReason = $Context.TargetObject.DenialOrCancelingReason
}
else
{
    $denialOrCancelingReason = ""
}

$reportEntry | Add-Member -Name "Denial or Canceling Reason" -Value $denialOrCancelingReason -MemberType NoteProperty
$reportEntry | Add-Member -Name "Operation Description" -Value $Context.TargetObject.DescriptionOfOperationToApprove -MemberType NoteProperty

# Import the CSV file
try
{
    [System.Object[]]$rows = Import-Csv $csvFilePath
}
catch
{
    $rows = $NULL
}

# Add a new row to the CSV file
if ($rows)
{
    $rows += $reportEntry
}
else
{
    $rows = $reportEntry
}

# Save changes
$rows | Export-Csv -Path $csvFilePath -NoTypeInformation
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers