Hello everyone,
I’m looking to export in CSV a report of all Azure AD Access Package assignments with their questions and answers.
Now everything is static EXCEPT the Questions+Answers which vary from one access package to the other. can be any number between 0 and “many” ![]()
My usual way of exporting to csv doesn’t work, please see the code below.
Could you please help me get a resolution please?
Code:
# 256-Color Foreground & Background Charts
##Change to beta profile##
Select-MgProfile -Name "beta"
##Import Modules##
Import-Module Microsoft.Graph.Identity.Governance
#### Define Variables ####
# Array to be exported in csv
[System.Collections.ArrayList]$outarray = @()
# Access Package ID
$accessPackageID = "5b0a0945-821a-4fbd-bf8b-82cf27df055e"
## Create CSV Headers
##Connect to MSGraph#
Connect-MgGraph -Scopes EntitlementManagement.Read.All
## Invokes the Graph API it will output as a JSON
##$x = Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/beta/identityGovernance/entitlementManagement/accessPackageAssignmentRequests?filter=accessPackage%2FId eq '$accessPackageID'"
$x = Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/beta/identityGovernance/entitlementManagement/accessPackageAssignmentRequests?filter=accessPackage%2FId eq '$accessPackageID'&expand=requestor"
##1st Question Text. Increment the 2nd Index to get all Questions Text. If NUll, No more questions left.
##$x.Value[0].answers.answeredQuestion[0].Text.defaultText
$questions = $x.Value[0].answers.answeredQuestion.Text.defaultText
$a = "Apple","Dog"
for($i=0; $i -le $x.value.Count; $i++){
## Create the Output hashtable
$properties = @{
##Requestor Name
Requestor = $x.value[$i].requestor.displayName
##Requestor Email
Email = $x.value[$i].requestor.principalName
##Time Request was created
CreatedDateTime = $x.Value[$i].createdDateTime
## Time Request Started
StartDateTime = $x.Value[$i].schedule.startDateTime
##Time Request Will End
EndDateTime = $x.Value[$i].schedule.expiration.endDateTime
##Business Justification
Justification = $x.Value[$i].justification
##Status of request
RequestStatus= $x.Value[$i].requestStatus ## Example FulfilledNotificationTriggered
}
$Obj = New-Object -TypeName psobject -Property $properties
$outarray.Add($obj) | Out-Null
}
$outarray | export-csv -Path .\AccessPackage.csv -NoTypeInformation
##DisConnect from MSGraph#
Disconnect-Graph
##Get the Desired Access Package by name
#$accessPackage = Get-MgEntitlementManagementAccessPackage -DisplayNameEq "Mentimeter Application"
##Get Access Package Requests
## As a parameter write -Debug to see everything that is returned and some metadata
#$requests = Get-MgEntitlementManagementAccessPackageAssignmentRequest -Debug -AccessPackageId $accessPackage.Id
##Get Access Package Assignments
#$assignments = Get-MgEntitlementManagementAccessPackageAssignment -AccessPackageId $accessPackage.Id
<#
##1st Question Text. Increment the 2nd Index to get all Questions Text. If NUll, No more questions left.
$x.Value[0].answers.answeredQuestion[0].Text.defaultText
##1st Question Answer
$x.Value[0].answers[0].value
##Time Request was created
$x.Value[0].createdDateTime
## Time Request Started
$x.Value[0].schedule.startDateTime
##Time Request Will End
$x.Value[0].schedule.expiration.endDateTime
##Business Justification
$x.Value[0].justification
##Status of request
$x.Value[0].requestStatus ## Example FulfilledNotificationTriggered
$x.Value[0].requestState ## Example Delivered
##Requestor
$x.value[0].requestor
##Requestor Name
$x.value[0].requestor.displayName
#>