IT Process Automation

 View Only
  • 1.  Start PAM SRF via powershell

    Posted Aug 13, 2019 03:33 PM
    Any chances someone has a working example of a powershell script to start a PAM SRF?

    thanks​


  • 2.  RE: Start PAM SRF via powershell
    Best Answer

    Posted Aug 14, 2019 09:51 AM
    Sure thing. I've had to do this a number of times for orphans and whatnot. The code I use (modified for example use):

    #########################################################################
    #
    # Request Credentials
    #
    #########################################################################

    try {
    if ($creds -eq $null) {
    $creds = Get-Credential -UserName $env:USERNAME -Message "Creds, please"
    }
    } catch {
    throw $_
    }

    #########################################################################
    #
    # Pull SRF information from PAM REST API
    #
    #########################################################################

    Write-Output "Accessing PAM API for SRF information..."

    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("Accept", 'application/json')
    $headers.Add("Path", '/Custom/Forms/RequestForm') ### Change Path To Your SRF Path ###
    $SrfObject = Invoke-RestMethod -Method Get -Uri 'https://YOUR_PAM.URL/api/rest/v1/srfs' -Credential $creds -Headers $headers ### UPDATE YOUR PAM DOMAIN HERE ###
    $Srf = $SrfObject.Response.Details.StartRequestForms.StartRequestForm | Where-Object {$_.path -eq 'YOUR_CRITERIA_HERE'} ### UPDATE WITH YOUR WHERE CLAUSE ###

    if ($Srf -eq $null) { throw "No SRF returned" }
    else { Write-Output " - SRF returned: $($actionData.actionDef.srf)" }

    #########################################################################
    #
    # Execute process
    #
    #########################################################################

    Write-Output "Building params for request ID $($data.request_id)..."

    $Params = @{"Request_ID" = $data.request_id; "Group_ID" = $data.group_id; "Offering_ID" = $data.offering_id; "submittingUser" = $data.req_by_user_id}

    $paramFinal = @()
    foreach ($kv in $Params.GetEnumerator()) {
    $paramFinal += "<Param><Name>$($kv.name)</Name><Value>$($kv.value)</Value></Param>"
    }

    Write-Output "Executing SRF..."

    #Submit SRF
    try {
    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("Accept", 'application/json')
    $body = @"
    <?xml version="1.0"?>
    <SubmitStartRequestForm>
    <Parameters>
    $($paramFinal -join '')
    </Parameters>
    <Options>
    </Options>
    </SubmitStartRequestForm>
    "@
    $SrfProcess = Invoke-RestMethod -Method Post -Uri "https://YOUR_PAM.URL/api/rest/v1/srfs/$($srf.ID)/submit" -Credential $creds -Headers $headers -Body $body -ContentType 'application/xml'
    Write-Output " - Outcome: $($SrfProcess.Response.Message)"
    } catch {
    throw $_
    }
    ​​
    This will pull & execute the appropriate SRF. I also have the code to attach a process to a request if needed. Make sure you update the domain where indicated & the Where-Object to fit your needs.


  • 3.  RE: Start PAM SRF via powershell

    Posted Aug 16, 2019 08:38 AM
    Thanks man!