Skip to content

Commit

Permalink
Initial Roles View
Browse files Browse the repository at this point in the history
  • Loading branch information
lwhitelock committed Nov 30, 2021
1 parent adff158 commit 4eb0f60
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ListRoles/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
]
}
32 changes: 32 additions & 0 deletions ListRoles/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"


# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."

# Interact with query parameters or the body of the request.
$TenantFilter = $Request.Query.TenantFilter
$SelectList = 'id', 'displayName', 'userPrincipalName'

[System.Collections.Generic.List[PSCustomObject]]$Roles = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/directoryRoles" -tenantid $TenantFilter

$GraphRequest = foreach ($Role in $Roles) {
[System.Collections.Generic.List[PSCustomObject]]$Members = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/directoryRoles/$($Role.id)/members?`$select=$($selectlist -join ',')" -tenantid $TenantFilter | select-object $SelectList
[PSCustomObject]@{
DisplayName = $Role.displayName
Description = $Role.description
Members = ($Members | ForEach-Object { $Return = "$($_.displayName)"; if ($_.userPrincipalName){$Return = $Return + " ($($_.userPrincipalName))"}; $Return}) -join ', '
}
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $GraphRequest
})

0 comments on commit 4eb0f60

Please sign in to comment.