Skip to content

Commit e228a4e

Browse files
author
rvdwegen
committed
Merge branch 'dev' of https://github.com/KelvinTegelaar/CIPP-API into dev
2 parents 3cfb562 + 56f7e9b commit e228a4e

22 files changed

Lines changed: 424 additions & 92 deletions

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@
2929
}
3030

3131
try {
32-
$RequestedReleases = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-QuarantineMessage' -cmdParams @{ PageSize = 1000; ReleaseStatus = 'Requested'; StartReceivedDate = (Get-Date).AddHours(-6) } -ErrorAction Stop | Select-Object -ExcludeProperty *data.type* | Sort-Object -Property ReceivedTime
32+
$cmdParams = @{
33+
PageSize = 1000
34+
ReleaseStatus = 'Requested'
35+
StartReceivedDate = (Get-Date).AddHours(-6)
36+
EndReceivedDate = (Get-Date).AddHours(0)
37+
}
38+
$RequestedReleases = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-QuarantineMessage' -cmdParams $cmdParams -ErrorAction Stop | Select-Object -ExcludeProperty *data.type* | Sort-Object -Property ReceivedTime
3339

3440
if ($RequestedReleases) {
3541
# Get the CIPP URL for the Quarantine link

Modules/CIPPCore/Public/Authentication/New-CIPPAPIConfig.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ function New-CIPPAPIConfig {
6565
Write-Information $CreateBody
6666
$Step = 'Creating Application'
6767
$APIApp = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/v1.0/applications' -AsApp $true -NoAuthCheck $true -type POST -body $CreateBody
68+
69+
try {
70+
$PolicyUpdate = Update-AppManagementPolicy -ApplicationId $APIApp.appId
71+
Write-Information $PolicyUpdate.PolicyAction
72+
} catch {
73+
Write-Information "Failed to update app management policy: $($_.Exception.Message)"
74+
}
75+
6876
Write-Information 'Creating password'
6977
$Step = 'Creating Application Password'
7078
$APIPassword = New-GraphPOSTRequest -uri "https://graph.microsoft.com/v1.0/applications/$($APIApp.id)/addPassword" -AsApp $true -NoAuthCheck $true -type POST -body "{`"passwordCredential`":{`"displayName`":`"Generated by API Setup`"}}" -maxRetries 3

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-CIPPDBCacheData.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ function Push-CIPPDBCacheData {
5050
'SecureScore'
5151
'PIMSettings'
5252
'Domains'
53-
'RoleEligibilitySchedules'
54-
'RoleManagementPolicies'
55-
'RoleAssignmentScheduleInstances'
5653
'B2BManagementPolicy'
5754
'AuthenticationFlowsPolicy'
5855
'DeviceRegistrationPolicy'
@@ -130,13 +127,16 @@ function Push-CIPPDBCacheData {
130127
}
131128
#endregion Conditional Access Licensed
132129

133-
#region Azure AD Premium P2 - Identity Protection features
130+
#region Azure AD Premium P2 - Identity Protection/PIM features
134131
if ($AzureADPremiumP2Capable) {
135132
$P2CacheFunctions = @(
136133
'RiskyUsers'
137134
'RiskyServicePrincipals'
138135
'ServicePrincipalRiskDetections'
139136
'RiskDetections'
137+
'RoleEligibilitySchedules'
138+
'RoleAssignmentSchedules'
139+
'RoleManagementPolicies'
140140
)
141141
foreach ($CacheFunction in $P2CacheFunctions) {
142142
$Batch.Add(@{

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Setup/Invoke-ExecCreateSAMApp.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ function Invoke-ExecCreateSAMApp {
6868
}
6969
} until ($attempt -gt 3)
7070
}
71+
72+
try {
73+
$AppPolicyStatus = Update-AppManagementPolicy
74+
Write-Information $AppPolicyStatus.PolicyAction
75+
} catch {
76+
Write-Warning "Error updating app management policy $($_.Exception.Message)."
77+
Write-Information ($_.InvocationInfo.PositionMessage)
78+
}
79+
7180
$AppPassword = (Invoke-RestMethod "https://graph.microsoft.com/v1.0/applications/$($AppId.id)/addPassword" -Headers @{ authorization = "Bearer $($Token.access_token)" } -Method POST -Body '{"passwordCredential":{"displayName":"CIPPInstall"}}' -ContentType 'application/json').secretText
7281

7382
if ($env:AzureWebJobsStorage -eq 'UseDevelopmentStorage=true' -or $env:NonLocalHostAzurite -eq 'true') {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ function Invoke-ExecSendPush {
5151
$SPID = (New-GraphPostRequest -uri 'https://graph.microsoft.com/v1.0/servicePrincipals' -tenantid $TenantFilter -type POST -body $SPBody -AsApp $true).id
5252
}
5353

54+
try {
55+
$PolicyUpdate = Update-AppManagementPolicy -TenantFilter $TenantFilter -ApplicationId $MFAAppID
56+
Write-Information $PolicyUpdate.PolicyAction
57+
} catch {
58+
Write-Information "Failed to update app management policy: $($_.Exception.Message)"
59+
}
5460

5561
$PassReqBody = @{
5662
'passwordCredential' = @{

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Invoke-SetAuthMethod.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@ function Invoke-SetAuthMethod {
1515
$State = if ($Request.Body.state -eq 'enabled') { $true } else { $false }
1616
$TenantFilter = $Request.Body.tenantFilter
1717
$AuthenticationMethodId = $Request.Body.Id
18-
18+
$GroupIds = $Request.Body.GroupIds
1919

2020
try {
21-
$Result = Set-CIPPAuthenticationPolicy -Tenant $TenantFilter -APIName $APIName -AuthenticationMethodId $AuthenticationMethodId -Enabled $State -Headers $Headers
21+
$Params = @{
22+
Tenant = $TenantFilter
23+
APIName = $APIName
24+
AuthenticationMethodId = $AuthenticationMethodId
25+
Enabled = $State
26+
Headers = $Headers
27+
}
28+
if ($GroupIds) {
29+
$Params.GroupIds = @($GroupIds)
30+
}
31+
$Result = Set-CIPPAuthenticationPolicy @Params
2232
$StatusCode = [HttpStatusCode]::OK
2333
} catch {
2434
$Result = $_.Exception.Message

Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-UpdateTokensTimer.ps1

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,21 @@ function Start-UpdateTokensTimer {
3939
# Check application secret expiration for $env:ApplicationId and generate a new application secret if expiration is within 30 days.
4040
try {
4141
$AppId = $env:ApplicationID
42-
$PasswordCredentials = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/applications(appId='$AppId')?`$select=id,passwordCredentials" -NoAuthCheck $true -AsApp $true -ErrorAction Stop
42+
$AppRegistration = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/applications(appId='$AppId')?`$select=id,passwordCredentials,servicePrincipalLockConfiguration" -NoAuthCheck $true -AsApp $true -ErrorAction Stop
4343
# sort by latest expiration date and get the first one
44-
$LastPasswordCredential = $PasswordCredentials.passwordCredentials | Sort-Object -Property endDateTime -Descending | Select-Object -First 1
44+
$LastPasswordCredential = $AppRegistration.passwordCredentials | Sort-Object -Property endDateTime -Descending | Select-Object -First 1
45+
46+
try {
47+
$AppPolicyStatus = Update-AppManagementPolicy
48+
Write-Information $AppPolicyStatus.PolicyAction
49+
} catch {
50+
Write-Warning "Error updating app management policy $($_.Exception.Message)."
51+
Write-Information ($_.InvocationInfo.PositionMessage)
52+
}
53+
4554
if ($LastPasswordCredential.endDateTime -lt (Get-Date).AddDays(30).ToUniversalTime()) {
4655
Write-Information "Application secret for $AppId is expiring soon. Generating a new application secret."
47-
$AppSecret = New-GraphPostRequest -uri "https://graph.microsoft.com/v1.0/applications/$($PasswordCredentials.id)/addPassword" -Body '{"passwordCredential":{"displayName":"UpdateTokens"}}' -NoAuthCheck $true -AsApp $true -ErrorAction Stop
56+
$AppSecret = New-GraphPostRequest -uri "https://graph.microsoft.com/v1.0/applications/$($AppRegistration.id)/addPassword" -Body '{"passwordCredential":{"displayName":"UpdateTokens"}}' -NoAuthCheck $true -AsApp $true -ErrorAction Stop
4857
Write-Information "New application secret generated for $AppId. Expiration date: $($AppSecret.endDateTime)."
4958
} else {
5059
Write-Information "Application secret for $AppId is valid until $($LastPasswordCredential.endDateTime). No need to generate a new application secret."
@@ -77,6 +86,20 @@ function Start-UpdateTokensTimer {
7786
} else {
7887
Write-Information "No expired application secrets found for $AppId."
7988
}
89+
90+
if (!$AppRegistration.servicePrincipalLockConfiguration.isEnabled) {
91+
Write-Warning "Service principal lock configuration is not enabled for $AppId"
92+
$Body = @{
93+
servicePrincipalLockConfiguration = @{
94+
isEnabled = $true
95+
allProperties = $true
96+
}
97+
} | ConvertTo-Json
98+
New-GraphPOSTRequest -type PATCH -uri "https://graph.microsoft.com/v1.0/applications/$($AppRegistration.id)" -Body $Body -NoAuthCheck $true -AsApp $true -ErrorAction Stop
99+
Write-Information "Service principal lock configuration has been enabled for application $AppId."
100+
Write-LogMessage -API 'Update Tokens' -message "Service principal lock configuration has been enabled for application $AppId." -sev 'Info'
101+
}
102+
80103
} catch {
81104
Write-Warning "Error updating application secret $($_.Exception.Message)."
82105
Write-Information ($_.InvocationInfo.PositionMessage)

Modules/CIPPCore/Public/Get-CIPPCalendarPermissionReport.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ function Get-CIPPCalendarPermissionReport {
3131
)
3232

3333
try {
34-
Write-LogMessage -API 'CalendarPermissionReport' -tenant $TenantFilter -message 'Generating calendar permission report' -sev Info
35-
3634
# Handle AllTenants
3735
if ($TenantFilter -eq 'AllTenants') {
3836
# Get all tenants that have calendar data

Modules/CIPPCore/Public/Get-CIPPIntunePolicy.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ function Get-CIPPIntunePolicy {
3535
$iOSPolicies = ($BulkResults | Where-Object { $_.id -eq 'iOSPolicies' }).body.value
3636

3737
if ($DisplayName) {
38-
$androidPolicy = $androidPolicies | Where-Object -Property displayName -EQ $DisplayName
39-
$iOSPolicy = $iOSPolicies | Where-Object -Property displayName -EQ $DisplayName
38+
$androidPolicy = $androidPolicies | Where-Object -Property displayName -EQ $DisplayName | Sort-Object -Property lastModifiedDateTime -Descending | Select-Object -First 1
39+
$iOSPolicy = $iOSPolicies | Where-Object -Property displayName -EQ $DisplayName | Sort-Object -Property lastModifiedDateTime -Descending | Select-Object -First 1
4040

4141
# Return the matching policy (Android or iOS) - using full data from bulk request
4242
if ($androidPolicy) {
@@ -92,7 +92,7 @@ function Get-CIPPIntunePolicy {
9292

9393
if ($DisplayName) {
9494
$policies = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL" -tenantid $tenantFilter
95-
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName
95+
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName | Sort-Object -Property lastModifiedDateTime -Descending | Select-Object -First 1
9696
if ($policy) {
9797
$policyDetails = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL('$($policy.id)')?`$expand=scheduledActionsForRule(`$expand=scheduledActionConfigurations)" -tenantid $tenantFilter
9898
$policyJson = ConvertTo-Json -InputObject $policyDetails -Depth 100 -Compress
@@ -122,7 +122,7 @@ function Get-CIPPIntunePolicy {
122122

123123
if ($DisplayName) {
124124
$policies = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL" -tenantid $tenantFilter
125-
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName
125+
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName | Sort-Object -Property lastModifiedDateTime -Descending | Select-Object -First 1
126126
if ($policy) {
127127
$definitionValues = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL('$($policy.id)')/definitionValues" -tenantid $tenantFilter
128128
$policy | Add-Member -MemberType NoteProperty -Name 'definitionValues' -Value $definitionValues -Force
@@ -237,7 +237,7 @@ function Get-CIPPIntunePolicy {
237237

238238
if ($DisplayName) {
239239
$policies = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL" -tenantid $tenantFilter
240-
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName
240+
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName | Sort-Object -Property lastModifiedDateTime -Descending | Select-Object -First 1
241241
if ($policy) {
242242
$policyDetails = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL('$($policy.id)')" -tenantid $tenantFilter
243243
$policyDetails = $policyDetails | Select-Object * -ExcludeProperty id, lastModifiedDateTime, '@odata.context', 'ScopeTagIds', 'supportsScopeTags', 'createdDateTime'
@@ -270,7 +270,7 @@ function Get-CIPPIntunePolicy {
270270

271271
if ($DisplayName) {
272272
$policies = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL" -tenantid $tenantFilter
273-
$policy = $policies | Where-Object -Property Name -EQ $DisplayName
273+
$policy = $policies | Where-Object -Property Name -EQ $DisplayName | Sort-Object -Property lastModifiedDateTime -Descending | Select-Object -First 1
274274
if ($policy) {
275275
$policyDetails = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL('$($policy.id)')?`$expand=settings" -tenantid $tenantFilter
276276
$policyDetails = $policyDetails | Select-Object name, description, settings, platforms, technologies, templateReference
@@ -303,7 +303,7 @@ function Get-CIPPIntunePolicy {
303303

304304
if ($DisplayName) {
305305
$policies = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL" -tenantid $tenantFilter
306-
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName
306+
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName | Sort-Object -Property lastModifiedDateTime -Descending | Select-Object -First 1
307307
if ($policy) {
308308
$policyDetails = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL('$($policy.id)')" -tenantid $tenantFilter
309309
$policyDetails = $policyDetails | Select-Object * -ExcludeProperty id, lastModifiedDateTime, '@odata.context', 'ScopeTagIds', 'supportsScopeTags', 'createdDateTime'
@@ -336,7 +336,7 @@ function Get-CIPPIntunePolicy {
336336

337337
if ($DisplayName) {
338338
$policies = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL" -tenantid $tenantFilter
339-
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName
339+
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName | Sort-Object -Property lastModifiedDateTime -Descending | Select-Object -First 1
340340
if ($policy) {
341341
$policyDetails = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL('$($policy.id)')" -tenantid $tenantFilter
342342
$policyDetails = $policyDetails | Select-Object * -ExcludeProperty id, lastModifiedDateTime, '@odata.context', 'ScopeTagIds', 'supportsScopeTags', 'createdDateTime'
@@ -369,7 +369,7 @@ function Get-CIPPIntunePolicy {
369369

370370
if ($DisplayName) {
371371
$policies = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL" -tenantid $tenantFilter
372-
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName
372+
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName | Sort-Object -Property lastModifiedDateTime -Descending | Select-Object -First 1
373373
if ($policy) {
374374
$policyDetails = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL('$($policy.id)')" -tenantid $tenantFilter
375375
$policyDetails = $policyDetails | Select-Object * -ExcludeProperty id, lastModifiedDateTime, '@odata.context', 'ScopeTagIds', 'supportsScopeTags', 'createdDateTime'
@@ -402,7 +402,7 @@ function Get-CIPPIntunePolicy {
402402

403403
if ($DisplayName) {
404404
$policies = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL" -tenantid $tenantFilter
405-
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName
405+
$policy = $policies | Where-Object -Property displayName -EQ $DisplayName | Sort-Object -Property lastModifiedDateTime -Descending | Select-Object -First 1
406406
if ($policy) {
407407
$policyDetails = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL('$($policy.id)')" -tenantid $tenantFilter
408408
$policyDetails = $policyDetails | Select-Object * -ExcludeProperty id, lastModifiedDateTime, '@odata.context', 'ScopeTagIds', 'supportsScopeTags', 'createdDateTime'

0 commit comments

Comments
 (0)