# Powershell script : Accessing attributes within accountRequest

**URL:** <https://developer.sailpoint.com/discuss/t/powershell-script-accessing-attributes-within-accountrequest/18584>\
**Category:** SHF Discussion and Questions\
**Tags:** sailpoint-identity-security\
**Created:** [October 4, 2023, 9:11am UTC](https://developer.sailpoint.com/discuss/t/powershell-script-accessing-attributes-within-accountrequest/18584 "2023-10-04T09:11:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JosquinClv](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@JosquinClv](https://developer.sailpoint.com/discuss/u/JosquinClv)\
**Post date:** [October 4, 2023, 9:11am UTC](https://developer.sailpoint.com/discuss/t/powershell-script-accessing-attributes-within-accountrequest/18584/1 "2023-10-04T09:11:21Z")

</div>

Hello developer community,

I got this account request that I’m catching in an afterModify rule

```auto
<AccountRequest application="AD [source]" op="Modify" nativeIdentity="CN=Bus Qo,OU=Users,DC=com">
  <Attributes>
    <Map>
      <entry key="cloudPreviousValues">
        <value>
          <Map>
            <entry key="extensionAttribute4" value="active" />
          </Map>
        </value>
      </entry>
    </Map>
  </Attributes>
  <AttributeRequest op="Set" name="extensionAttribute4" value="onboarding" />
</AccountRequest>

```

I am only able to get the AttributeRequest (key and value) that I can put in a map.  
For the others attributes within the accountRequest (like cloudPreviousValues) I cannot access it.

Here is my code `Try{  
if($enableDebug) {  
LogToFile(“$logDate - Entering SailPoint rule”)  
}  
Add-type -path “C:\SailPoint\IQService\Utils.dll”;  
$sReader = New-Object System.IO.StringReader([System.String]$env:Request);  
$xmlReader = System.xml.XmlTextReader;  
$requestObject = New-Object Sailpoint.Utils.objects.AccountRequest($xmlReader);  
$resultObject = New-Object Sailpoint.Utils.objects.ServiceResult;

```
$requestAsString = $env:Request
if($enableDebug) {
    LogToFile("$logDate - Request as XML object is: $requestAsString")
}

$requestMap = @{}
if ($requestObject) {
    foreach ($attrib in $requestObject.AttributeRequests) {
            $nameAttr = $attrib.Name
            $valueAttr = $attrib.Value;
            LogToFile("$logDate - Request as XML object2 is: $nameAttr")
            LogToFile("$logDate - Request as XML object2 is: $valueAttr")
            $requestMap.Add($nameAttr,$valueAttr);
    }
}

LogToFile("$logDate - Request as xmlReader : $xmlReader") 
$ADID2 = Get-AttributeValueFromAccountRequest $requestObject "extensionAttribute4"
$ADID = Get-AttributeValueFromAccountRequest $requestObject "cloudPreviousValues"
$ADID0 = Get-AttributeValueFromAccountRequest $requestObject "Attributes"

#$managerMail = $requestMap['managerMail'];extensionAttribute4
#$cloudPreviousValues = $requestAsString| Select-Object -ExpandProperty Keys
LogToFile("$logDate - Request as requestMap: $requestMap")

LogToFile("$logDate - Request as ADID0: $ADID2")
LogToFile("$logDate - Request as ADID0: $ADID")
LogToFile("$logDate - Request as ADID0: $ADID0")

```

`

I tried to load my requestAccess object while pointing towards its attributes  
`$requestObject.Attributes` but I got this error : Error: Item = → Message = Exception calling “.ctor” with “1” argument(s): "AccountRequest element not found.

Do you know how if I can access those attributes ?  
thanks in advance,

---

<div class="post-metadata">

**Author:** ![jesvin90](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/jesvin90/32/5301_2.png) [@jesvin90](https://developer.sailpoint.com/discuss/u/jesvin90)\
**Post date:** [October 4, 2023, 12:06pm UTC](https://developer.sailpoint.com/discuss/t/powershell-script-accessing-attributes-within-accountrequest/18584/2 "2023-10-04T12:06:41Z")

</div>

> [@JosquinClv](#):
>
> `extensionAttribute4`

Hi Josquin,

Can you try this and see if it works :

$attributesMap = $requestObject.Attributes

$attributesMap.cloudPreviousValues.extensionAttribute4 OR $attributesMap[‘cloudPreviousValues’][‘extensionAttribute4’]

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [December 3, 2023, 12:06pm UTC](https://developer.sailpoint.com/discuss/t/powershell-script-accessing-attributes-within-accountrequest/18584/3 "2023-12-03T12:06:58Z")

</div>

Closed on December 3, 2023, 12:06pm UTC

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