Skip to content

Commit dc9d9cb

Browse files
authored
Merge pull request #495 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 35985a5 + 8509fbd commit dc9d9cb

File tree

4 files changed

+117
-8
lines changed

4 files changed

+117
-8
lines changed

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertEntraConnectSyncStatus.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ function Get-CIPPAlertEntraConnectSyncStatus {
2020
$LastPasswordSync = $ConnectSyncStatus.onPremisesLastPasswordSyncDateTime
2121
$SyncDateTime = $ConnectSyncStatus.onPremisesLastSyncDateTime
2222
# Get the older of the two sync times
23-
$LastSync = if ($SyncDateTime -lt $LastPasswordSync) { $SyncDateTime } else { $LastPasswordSync }
23+
$LastSync = if ($SyncDateTime -lt $LastPasswordSync) { $SyncDateTime; $Cause = 'DirectorySync' } else { $LastPasswordSync; $Cause = 'PasswordSync' }
2424

2525
if ($LastSync -lt (Get-Date).AddHours(-$Hours).ToUniversalTime()) {
26-
$AlertData = "Entra Connect Sync for $($TenantFilter) has not run for over $Hours hours. Last sync was at $($LastSync.ToString('o'))"
26+
27+
$AlertData = @{
28+
Message = "Entra Connect $Cause for $($TenantFilter) has not run for over $Hours hours. Last sync was at $($LastSync.ToString('o'))"
29+
LastSync = $LastSync
30+
Cause = $Cause
31+
LastPasswordSync = $LastPasswordSync
32+
LastDirectorySync = $SyncDateTime
33+
Tenant = $TenantFilter
34+
}
2735
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
2836
}
2937
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListUserSettings.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ function Invoke-ListUserSettings {
2020
$UserSettings = $UserSettings.JSON | ConvertFrom-Json -Depth 10 -ErrorAction SilentlyContinue
2121
} catch {
2222
Write-Warning "Failed to convert UserSettings JSON: $($_.Exception.Message)"
23+
}
24+
25+
if (!$UserSettings) {
2326
$UserSettings = [pscustomobject]@{
2427
direction = 'ltr'
2528
paletteMode = 'light'
@@ -36,8 +39,7 @@ function Invoke-ListUserSettings {
3639
try {
3740
$UserSpecificSettings = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'UserSettings' and RowKey eq '$Username'"
3841
$UserSpecificSettings = $UserSpecificSettings.JSON | ConvertFrom-Json -Depth 10 -ErrorAction SilentlyContinue
39-
}
40-
catch {
42+
} catch {
4143
Write-Warning "Failed to convert UserSpecificSettings JSON: $($_.Exception.Message)"
4244
}
4345

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/GDAP/Invoke-ExecGDAPInvite.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ function Invoke-ExecGDAPInvite {
9494
'OnboardingUrl' = $OnboardingUrl
9595
'RoleMappings' = [string](@($RoleMappings) | ConvertTo-Json -Depth 10 -Compress)
9696
'Technician' = [string]$Technician
97+
'Reference' = if ($Reference) { [string]$Reference } else { $null }
9798
}
9899

99-
if ($Reference) { $InviteEntity['Reference'] = [string]$Reference }
100-
101100
Add-CIPPAzDataTableEntity @Table -Entity $InviteEntity
102101

103102
$Message = 'GDAP relationship invite created. Log in as a Global Admin in the new tenant to approve the invite.'
@@ -133,10 +132,9 @@ function Invoke-ExecGDAPInvite {
133132
'PartitionKey' = 'invite'
134133
'RowKey' = $InviteId
135134
'Technician' = $Technician
135+
'Reference' = if ($Reference) { $Reference } else { $null }
136136
}
137137

138-
if ($Reference) { $InviteEntity['Reference'] = $Reference }
139-
140138
Add-CIPPAzDataTableEntity @Table -Entity $InviteEntity -OperationType 'UpsertMerge'
141139
$Message = 'Invite updated'
142140
} else {
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
function Invoke-CIPPStandardBitLockerKeysForOwnedDevice {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
.COMPONENT
6+
(APIName) BitLockerKeysForOwnedDevice
7+
.SYNOPSIS
8+
(Label) Restrict users from recovering BitLocker keys for owned devices
9+
.DESCRIPTION
10+
(Helptext) Controls whether standard users can recover BitLocker keys for devices they own via Microsoft 365 portals.
11+
(DocsDescription) Updates the default user role setting that governs access to BitLocker recovery keys for owned devices. This allows administrators to either permit self-service recovery or require helpdesk involvement through Microsoft Entra authorization policies.
12+
.NOTES
13+
CAT
14+
Entra (AAD) Standards
15+
TAG
16+
"NIST CSF 2.0 (PR.AA-05)"
17+
EXECUTIVETEXT
18+
Ensures administrators retain control over BitLocker recovery secrets when required, while still allowing flexibility to enable self-service recovery when business needs demand it.
19+
ADDEDCOMPONENT
20+
{"type":"autoComplete","multiple":false,"creatable":false,"label":"Select state","name":"standards.BitLockerKeysForOwnedDevice.state","options":[{"label":"Restrict","value":"restrict"},{"label":"Allow","value":"allow"}]}
21+
IMPACT
22+
Medium Impact
23+
ADDEDDATE
24+
2025-10-12
25+
POWERSHELLEQUIVALENT
26+
Update-MgBetaPolicyAuthorizationPolicy
27+
RECOMMENDEDBY
28+
"CIPP"
29+
UPDATECOMMENTBLOCK
30+
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
31+
.LINK
32+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards
33+
#>
34+
35+
param($Tenant, $Settings)
36+
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'BitLockerKeysForOwnedDevice'
37+
38+
$StateValue = $Settings.state.value ?? $Settings.state
39+
if ([string]::IsNullOrWhiteSpace($StateValue)) {
40+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'BitLockerKeysForOwnedDevice: Invalid state parameter set.' -sev Error
41+
return
42+
}
43+
44+
switch ($StateValue.ToLowerInvariant()) {
45+
'restrict' { $DesiredValue = $false; $DesiredLabel = 'restricted'; break }
46+
'allow' { $DesiredValue = $true; $DesiredLabel = 'allowed'; break }
47+
default {
48+
Write-LogMessage -API 'Standards' -tenant $tenant -message "BitLockerKeysForOwnedDevice: Unsupported state value '$StateValue'." -sev Error
49+
return
50+
}
51+
}
52+
53+
try {
54+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authorizationPolicy/authorizationPolicy' -tenantid $Tenant
55+
} catch {
56+
$ErrorMessage = Get-CippException -Exception $_
57+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the BitLockerKeysForOwnedDevice state for $Tenant. Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
58+
return
59+
}
60+
$CurrentValue = [bool]$CurrentState.defaultUserRolePermissions.allowedToReadBitLockerKeysForOwnedDevice
61+
$StateIsCorrect = ($CurrentValue -eq $DesiredValue)
62+
63+
if ($Settings.remediate -eq $true) {
64+
if ($StateIsCorrect -eq $true) {
65+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Users are already $DesiredLabel from recovering BitLocker keys for their owned devices." -sev Info
66+
} else {
67+
try {
68+
$BodyObject = @{ defaultUserRolePermissions = @{ allowedToReadBitLockerKeysForOwnedDevice = $DesiredValue } }
69+
$BodyJson = $BodyObject | ConvertTo-Json -Depth 4 -Compress
70+
$null = New-GraphPOSTRequest -tenantid $tenant -Uri 'https://graph.microsoft.com/beta/policies/authorizationPolicy/authorizationPolicy' -Type patch -Body $BodyJson
71+
$ActionMessage = if ($DesiredValue) { 'Allowed users to recover BitLocker keys for their owned devices.' } else { 'Restricted users from recovering BitLocker keys for their owned devices.' }
72+
Write-LogMessage -API 'Standards' -tenant $tenant -message $ActionMessage -sev Info
73+
74+
75+
# Update current state variables to reflect the change immediately if running remediate and report/alert together
76+
$CurrentState.defaultUserRolePermissions.allowedToReadBitLockerKeysForOwnedDevice = $DesiredValue
77+
$CurrentValue = $DesiredValue
78+
$StateIsCorrect = $true
79+
} catch {
80+
$ErrorMessage = Get-CippException -Exception $_
81+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to $StateValue users to recover BitLocker keys for their owned devices: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
82+
}
83+
}
84+
}
85+
86+
if ($Settings.alert -eq $true) {
87+
if ($StateIsCorrect -eq $true) {
88+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Users are $DesiredLabel to recover BitLocker keys for their owned devices as configured." -sev Info
89+
} else {
90+
$CurrentLabel = if ($CurrentValue) { 'allowed' } else { 'restricted' }
91+
$AlertMessage = "Users are $CurrentLabel to recover BitLocker keys for their owned devices but should be $DesiredLabel."
92+
Write-StandardsAlert -message $AlertMessage -object $CurrentState -tenant $tenant -standardName 'BitLockerKeysForOwnedDevice' -standardId $Settings.standardId
93+
Write-LogMessage -API 'Standards' -tenant $tenant -message $AlertMessage -sev Info
94+
}
95+
}
96+
97+
if ($Settings.report -eq $true) {
98+
Set-CIPPStandardsCompareField -FieldName 'standards.BitLockerKeysForOwnedDevice' -FieldValue $StateIsCorrect -Tenant $tenant
99+
Add-CIPPBPAField -FieldName 'BitLockerKeysForOwnedDevice' -FieldValue $CurrentValue -StoreAs bool -Tenant $tenant
100+
}
101+
}

0 commit comments

Comments
 (0)