Create Bulk Access Requests in ISC

I have updated the script where you can now create access request for multiple users i.e. 100 or 200 users using a single CSV file for multiple entitlements.

$CurrentDate = Get-Date
$CurrentDates = $CurrentDate.ToString(‘MM-dd-yyyy_hh-mm-ss’)

=== Credentials ===

---- Config ----

$Tenant = “tenant” # e.g., contoso
$TokenEndpoint = “https://$Tenant.api.identitynow.com/oauth/token
$ClientId = “-----”
$ClientSecret = “—”

---- Token Request (must be x-www-form-urlencoded) ----

$tokenBody = @{
grant_type = “client_credentials”
client_id = $ClientId
client_secret = $ClientSecret

Optional: scope. If omitted, SailPoint may default to sp:scopes:all per client config.

scope = “sp:scopes:default”

}

$tokenResponse = Invoke-RestMethod -Method POST -Uri $TokenEndpoint -Body $tokenBody -ContentType “application/x-www-form-urlencoded”

Validate we actually got a token

if (-not $tokenResponse.access_token) {
throw “Token request failed. Response: $($tokenResponse | ConvertTo-Json -Depth 5)”
}

$Token = $tokenResponse.access_token
$Headers = @{ Authorization = “Bearer $Token” }

=== Read CSV Input ===

$csvPath = “C:\Users\Karan\Assign-Users-Entitlements.csv”
$entries = Import-Csv -Path $csvPath

=== Output CSV Setup ===

$CombinedData = @()
$logPath = “C:\Users\Karan\Assign-Bulk-Access-$CurrentDates.csv”

=== Loop Through CSV Entries ===

foreach ($entry in $entries) {
$userId = $entry.UserId
$entitlementId = $entry.EntitlementId

$body = @{
    requestedFor   = @($userId)
    requestType    = "GRANT_ACCESS"
    requestedItems = @(
        @{
            type    = "ENTITLEMENT"
            id      = $entitlementId
            comment = "Access Request is created as per request from Karan"
        }
    )
}

$jsonBody = $body | ConvertTo-Json -Depth 5

$params = @{
    method      = "POST"
    uri         = "https://$Tenant.api.identitynow.com/v3/access-requests"
    body        = $jsonBody
    headers     = @{ 'Authorization' = "Bearer $token" }
    ContentType = "application/json"
}

try {
    $response = Invoke-RestMethod @params
    Write-Host "SUCCESS: Assigned entitlement $entitlementId to user $userId" -ForegroundColor Green

    $CombinedData += [PSCustomObject]@{
        RequestedFor    = $userId
        RequestType     = "GRANT_ACCESS"
        ItemType        = "ENTITLEMENT"
        ItemId          = $entitlementId
        ItemComment     = "Access Request is created as per request from Karan"
        Status          = "Success"
    }
} catch {
    Write-Host "ERROR: Failed to assign entitlement $entitlementId to user $userId" -ForegroundColor Red
    Write-Host $_.Exception.Message -ForegroundColor Red

    $CombinedData += [PSCustomObject]@{
        RequestedFor    = $userId
        RequestType     = "GRANT_ACCESS"
        ItemType        = "ENTITLEMENT"
        ItemId          = $entitlementId
        ItemComment     = "Access Request is created as per request from Karan"
        Status          = "Failed: $($_.Exception.Message)"
    }
}

}

=== Export to CSV ===

$CombinedData | Export-Csv -Path $logPath -NoTypeInformation -Append
Write-Host “CSV Exported to $logPath”

CSV contains UserId and EntitlementID Headers.