Capturing $requestObject for debugging

Hey everyone, I’m working on an after create script and trying to access some of the values inside of $requestObject.AttributeRequests so that I can populate some data in an email being sent by a powershell script.

Do you know how I can capture the entirety of $requestObject (including all account provisioning values like UPN and mail) so that I can debug the script in VS Code?

Or alternatively, how I can access the data I’m looking for? I’ve gotten this far in PS with the below code and my logs report out the right attribute that I’m looking for but when I drill down into $mailObject.value, it doesn’t like the data type. Do I just need to “out-string” it?

$mailObject = $requestObject.AttributeRequests | Where-Object {$_.Name -eq "Mail"}

I only use PS when I have to so there are definitely more elegant solutions, but this is the general method I’ve used:

Add-Type -path Utils.dll

# Log AccountRequest XML to file
$env:Request | Out-File "tmp.log" -Append

# Parse request object
$sReader = New-Object System.IO.StringReader([System.String]$env:Request)
$xmlReader = [System.xml.XmlTextReader]([sailpoint.utils.xml.XmlUtil]::getReader($sReader))
$requestObject = New-Object Sailpoint.Utils.objects.AccountRequest($xmlReader)

# Find attribute value
$mail = $null
foreach ($attributeRequest in $requestObject.AttributeRequests) {
    if ($attributeRequest.Name -eq "mail") {
        $mail = $attributeRequest.Value
        break
    }
}
"value: $mail" | Out-File "tmp.log" -Append

Hi @WyssAJ01,

Try this :

function LogToFile([String] $info) {
    $info | Out-File $logFile -Append
}
$sReader = New-Object System.IO.StringReader([System.String]$requestString);
$xmlReader = [System.xml.XmlTextReader]([sailpoint.utils.xml.XmlUtil]::getReader($sReader));
$requestObject = New-Object Sailpoint.Utils.objects.AccountRequest($xmlReader);

To get the whole content :

LogToFile($requestObject | Out-String)

To get a specific value :

($requestObject.AttributeRequests | Where-Object Name -eq $targetAttribute).Value

So, I found this that ended up being the answer.

Apparently google is better at search than discourse is. It doesn’t capture the whole request object like I was hoping for so that I could basically “replay” a provisioning event without actually having to build an AD account, but it solves the immediate need of finding the attribute I was looking for inside the request.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.