Skip to content

Commit 73f75c8

Browse files
alert on licensed users with roles
1 parent 1ca079e commit 73f75c8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function Get-CIPPAlertLicensedUsersWithRoles {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
#>
6+
[CmdletBinding()]
7+
param (
8+
[Parameter(Mandatory = $false)]
9+
[Alias('input')]
10+
$InputValue,
11+
$TenantFilter
12+
)
13+
14+
# Get all users with assigned licenses
15+
$LicensedUsers = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users?`$top=999&`$select=userPrincipalName,assignedLicenses,displayName" -tenantid $TenantFilter | Where-Object { $_.assignedLicenses -and $_.assignedLicenses.Count -gt 0 }
16+
if (-not $LicensedUsers -or $LicensedUsers.Count -eq 0) {
17+
Write-Information "No licensed users found for tenant $TenantFilter"
18+
return $true
19+
}
20+
# Get all directory roles with their members
21+
$DirectoryRoles = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/directoryRoles?`$expand=members" -tenantid $TenantFilter
22+
if (-not $DirectoryRoles -or $DirectoryRoles.Count -eq 0) {
23+
Write-Information "No directory roles found for tenant $TenantFilter"
24+
return
25+
}
26+
$UsersToAlertOn = $LicensedUsers | Where-Object { $_.userPrincipalName -in $DirectoryRoles.members.userPrincipalName }
27+
28+
29+
if ($UsersToAlertOn.Count -gt 0) {
30+
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $UsersToAlertOn
31+
} else {
32+
Write-Information "No licensed users with roles found for tenant $TenantFilter"
33+
}
34+
35+
36+
}

0 commit comments

Comments
 (0)