Skip to content

Commit 8a04b30

Browse files
authored
Merge branch 'KelvinTegelaar:dev' into dev
2 parents 8d789eb + 6267eaf commit 8a04b30

20 files changed

Lines changed: 318 additions & 159 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function Get-CIPPAlertSharepointQuota {
2727
}
2828
$UsedStoragePercentage = [int](($sharepointQuota.GeoUsedStorageMB / $sharepointQuota.TenantStorageMB) * 100)
2929
if ($UsedStoragePercentage -gt $Value) {
30-
$AlertData = "SharePoint Storage is at $($UsedStoragePercentage)%. Your alert threshold is $($Value)%"
30+
$AlertData = "SharePoint Storage is at $($UsedStoragePercentage)% [$([math]::Round($sharepointQuota.GeoUsedStorageMB / 1024, 2)) GB/$([math]::Round($sharepointQuota.TenantStorageMB / 1024, 2)) GB]. Your alert threshold is $($Value)%"
3131
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
3232
}
3333
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Invoke-AddRoomMailbox.ps1

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Function Invoke-AddRoomMailbox {
1212

1313
$APIName = $TriggerMetadata.FunctionName
1414
$User = $request.headers.'x-ms-client-principal'
15+
1516
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1617

1718
# Write to the Azure Functions log stream.
@@ -20,6 +21,7 @@ Function Invoke-AddRoomMailbox {
2021

2122
$Results = [System.Collections.Generic.List[Object]]::new()
2223
$MailboxObject = $Request.body
24+
$Tenant = $MailboxObject.tenantid
2325
$AddRoomParams = [pscustomobject]@{
2426
Name = $MailboxObject.username
2527
DisplayName = $MailboxObject.displayName
@@ -30,30 +32,30 @@ Function Invoke-AddRoomMailbox {
3032
}
3133
# Interact with query parameters or the body of the request.
3234
try {
33-
$AddRoomRequest = New-ExoRequest -tenantid $($MailboxObject.tenantid) -cmdlet 'New-Mailbox' -cmdparams $AddRoomParams
35+
$AddRoomRequest = New-ExoRequest -tenantid $Tenant -cmdlet 'New-Mailbox' -cmdparams $AddRoomParams
3436
$Results.Add("Successfully created room: $($MailboxObject.DisplayName).")
35-
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Created room $($MailboxObject.DisplayName) with id $($AddRoomRequest.id)" -Sev 'Info'
37+
Write-LogMessage -user $User -API $APINAME -tenant $Tenant -message "Created room $($MailboxObject.DisplayName) with id $($AddRoomRequest.id)" -Sev 'Info'
3638

3739
# Block sign-in for the mailbox
3840
try {
39-
$Request = Set-CIPPSignInState -userid $AddRoomRequest.ExternalDirectoryObjectId -TenantFilter $($MailboxObject.tenantid) -APIName $APINAME -ExecutingUser $User -AccountEnabled $false
41+
$Request = Set-CIPPSignInState -userid $AddRoomRequest.ExternalDirectoryObjectId -TenantFilter $Tenant -APIName $APINAME -ExecutingUser $User -AccountEnabled $false
4042
$Results.add("Blocked sign-in for Room mailbox; $($MailboxObject.userPrincipalName)")
4143
} catch {
42-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
43-
$Results.add("Failed to block sign-in for Room mailbox: $($MailboxObject.userPrincipalName). Error: $ErrorMessage")
44+
$ErrorMessage = Get-CippException -Exception $_
45+
$Results.add("Failed to block sign-in for Room mailbox: $($MailboxObject.userPrincipalName). Error: $($ErrorMessage.NormalizedError)")
4446
}
45-
47+
$StatusCode = [HttpStatusCode]::OK
4648
} catch {
4749
$ErrorMessage = Get-CippException -Exception $_
48-
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Failed to create room: $($MailboxObject.DisplayName). Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
50+
Write-LogMessage -user $User -API $APINAME -tenant $Tenant -message "Failed to create room: $($MailboxObject.DisplayName). Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
4951
$Results.Add("Failed to create Room mailbox $($MailboxObject.userPrincipalName). $($ErrorMessage.NormalizedError)")
52+
$StatusCode = [HttpStatusCode]::Forbidden
5053
}
5154

52-
5355
$Body = [pscustomobject] @{ 'Results' = @($Results) }
5456
# Associate values to output bindings by calling 'Push-OutputBinding'.
5557
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
56-
StatusCode = [HttpStatusCode]::OK
58+
StatusCode = $StatusCode
5759
Body = $Body
5860
})
5961
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Invoke-AddSharedMailbox.ps1

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ Function Invoke-AddSharedMailbox {
1515

1616
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1717

18+
# Write to the Azure Functions log stream.
19+
Write-Host 'PowerShell HTTP trigger function processed a request.'
20+
1821
$Results = [System.Collections.ArrayList]@()
1922
$MailboxObject = $Request.body
23+
$Tenant = $MailboxObject.tenantid
2024
$Aliases = $MailboxObject.addedAliases -Split '\n'
2125

22-
# Write to the Azure Functions log stream.
23-
Write-Host 'PowerShell HTTP trigger function processed a request.'
2426
try {
2527

2628
$Email = "$($MailboxObject.username)@$($MailboxObject.domain)"
@@ -30,48 +32,51 @@ Function Invoke-AddSharedMailbox {
3032
'primarySMTPAddress' = $Email
3133
Shared = $true
3234
}
33-
$AddSharedRequest = New-ExoRequest -tenantid $MailboxObject.tenantid -cmdlet 'New-Mailbox' -cmdparams $BodyToShip
35+
$AddSharedRequest = New-ExoRequest -tenantid $Tenant -cmdlet 'New-Mailbox' -cmdparams $BodyToShip
3436
$Body = $Results.add("Successfully created shared mailbox: $Email.")
35-
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Created shared mailbox $($MailboxObject.displayname) with email $Email" -Sev 'Info'
37+
Write-LogMessage -user $User -API $APINAME -tenant $Tenant -message "Created shared mailbox $($MailboxObject.displayname) with email $Email" -Sev 'Info'
3638

3739
# Block sign-in for the mailbox
3840
try {
39-
$null = Set-CIPPSignInState -userid $AddSharedRequest.ExternalDirectoryObjectId -TenantFilter $($MailboxObject.tenantid) -APIName $APINAME -ExecutingUser $User -AccountEnabled $false
41+
$null = Set-CIPPSignInState -userid $AddSharedRequest.ExternalDirectoryObjectId -TenantFilter $Tenant -APIName $APINAME -ExecutingUser $User -AccountEnabled $false
4042
$Body = $Results.add("Blocked sign-in for shared mailbox $Email")
4143
} catch {
42-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
43-
$Body = $Results.add("Failed to block sign-in for shared mailbox $Email. Error: $ErrorMessage")
44+
$ErrorMessage = Get-CippException -Exception $_
45+
Write-LogMessage -user $User -API $APINAME -tenant $Tenant -message "Failed to block sign-in for shared mailbox $Email. Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
46+
$Body = $Results.add("Failed to block sign-in for shared mailbox $Email. Error: $($ErrorMessage.NormalizedError)")
4447
}
4548

46-
} catch {
47-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
48-
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Failed to create shared mailbox. Error: $ErrorMessage" -Sev 'Error'
49-
$Body = $Results.add("Failed to create Shared Mailbox. $ErrorMessage")
50-
}
49+
# Add aliases to the mailbox if any are provided
50+
if ($Aliases) {
51+
try {
52+
Start-Sleep 3 # Sleep since there is apparently a race condition with the mailbox creation if we don't delay for a lil bit
53+
$AliasBodyToShip = [pscustomobject] @{
54+
'Identity' = $AddSharedRequest.Guid
55+
'EmailAddresses' = @{'@odata.type' = '#Exchange.GenericHashTable'; Add = $Aliases }
56+
}
57+
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-Mailbox' -cmdparams $AliasBodyToShip -UseSystemMailbox $true
58+
Write-LogMessage -user $User -API $APINAME -tenant $Tenant -message "Added aliases to $Email : $($Aliases -join ',')" -Sev 'Info'
59+
$Body = $results.add("Added Aliases to $Email : $($Aliases -join ',')")
5160

52-
# Add aliases to the mailbox if any are provided
53-
if ($Aliases) {
54-
try {
55-
Start-Sleep 3 # Sleep since there is apparently a race condition with the mailbox creation if we don't delay for a lil bit
56-
$AliasBodyToShip = [pscustomobject] @{
57-
'Identity' = $AddSharedRequest.Guid
58-
'EmailAddresses' = @{'@odata.type' = '#Exchange.GenericHashTable'; Add = $Aliases }
61+
} catch {
62+
$ErrorMessage = Get-CippException -Exception $_
63+
Write-LogMessage -user $User -API $APINAME -tenant $Tenant -message "Failed to add aliases to $Email : $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
64+
$Body = $results.add("ERROR: Failed to add aliases to $Email : $($ErrorMessage.NormalizedError)")
5965
}
60-
$null = New-ExoRequest -tenantid $MailboxObject.tenantid -cmdlet 'Set-Mailbox' -cmdparams $AliasBodyToShip -UseSystemMailbox $true
61-
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Added aliases to $Email : $($Aliases -join ',')" -Sev 'Info'
62-
$Body = $results.add("Added Aliases to $Email : $($Aliases -join ',')")
63-
64-
} catch {
65-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
66-
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Failed to add aliases to $Email : $ErrorMessage" -Sev 'Error'
67-
$Body = $results.add("ERROR: Failed to add aliases to $Email : $ErrorMessage")
6866
}
67+
$StatusCode = [HttpStatusCode]::OK
68+
} catch {
69+
$ErrorMessage = Get-CippException -Exception $_
70+
Write-LogMessage -user $User -API $APINAME -tenant $Tenant -message "Failed to create shared mailbox. Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
71+
$Body = $Results.add("Failed to create Shared Mailbox. $($ErrorMessage.NormalizedError)")
72+
$StatusCode = [HttpStatusCode]::Forbidden
6973
}
7074

75+
7176
$Body = [pscustomobject] @{ 'Results' = @($results) }
7277
# Associate values to output bindings by calling 'Push-OutputBinding'.
7378
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
74-
StatusCode = [HttpStatusCode]::OK
79+
StatusCode = $StatusCode
7580
Body = $Body
7681
})
7782

Modules/CIPPCore/Public/GraphHelper/New-ExoRequest.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function New-ExoRequest {
139139
Method = 'POST'
140140
Body = $ExoBody
141141
Headers = $Headers
142-
ContentType = 'application/json'
142+
ContentType = 'application/json; charset=utf-8'
143143
}
144144

145145
$Return = Invoke-RestMethod @ExoRequestParams -ResponseHeadersVariable ResponseHeaders

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardActivityBasedTimeout.ps1

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ function Invoke-CIPPStandardActivityBasedTimeout {
4242
# Backwards compatibility for v5.7.0 and older
4343
if ($null -eq $Settings.timeout ) { $Settings.timeout = '01:00:00' }
4444

45-
$State = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies' -tenantid $tenant
46-
$StateIsCorrect = $State.definition -like "*$($Settings.timeout)*"
45+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies' -tenantid $tenant
46+
$StateIsCorrect = if ($CurrentState.definition -like "*$($Settings.timeout)*") { $true } else { $false }
4747

4848
If ($Settings.remediate -eq $true) {
4949
try {
50-
if (!$StateIsCorrect) {
50+
if ($StateIsCorrect -eq $true) {
51+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is already enabled and set to $($Settings.timeout)" -sev Info
52+
} else {
5153
$PolicyTemplate = @{
5254
displayName = 'DefaultTimeoutPolicy'
5355
isOrganizationDefault = $true
@@ -58,27 +60,24 @@ function Invoke-CIPPStandardActivityBasedTimeout {
5860
$body = ConvertTo-Json -InputObject $PolicyTemplate -Depth 10 -Compress
5961

6062
# Switch between parameter sets if the policy already exists
61-
if ($null -eq $State.id) {
63+
if ($null -eq $CurrentState.id) {
6264
$RequestType = 'POST'
6365
$URI = 'https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies'
6466
} else {
6567
$RequestType = 'PATCH'
66-
$URI = "https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies/$($State.id)"
68+
$URI = "https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies/$($CurrentState.id)"
6769
}
6870
New-GraphPostRequest -tenantid $tenant -Uri $URI -Type $RequestType -Body $body -ContentType 'application/json'
6971
Write-LogMessage -API 'Standards' -tenant $tenant -message "Enabled Activity Based Timeout with a value of $($Settings.timeout)" -sev Info
70-
} else {
71-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is already enabled and set to $($Settings.timeout)" -sev Info
7272
}
7373
} catch {
74-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
75-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to enable Activity Based Timeout a value of $($Settings.timeout). Error: $ErrorMessage" -sev Error
74+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to enable Activity Based Timeout a value of $($Settings.timeout)." -sev Error -LogData $_
7675
}
7776
}
7877

7978
if ($Settings.alert -eq $true) {
8079

81-
if ($StateIsCorrect) {
80+
if ($StateIsCorrect -eq $true) {
8281
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is enabled and set to $($Settings.timeout)" -sev Info
8382
} else {
8483
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is not set to $($Settings.timeout)" -sev Alert

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardDisableEmail.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@ function Invoke-CIPPStandardDisableEmail {
2929
param($Tenant, $Settings)
3030
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'DisableEmail'
3131

32-
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/Email' -tenantid $Tenant
33-
$State = if ($CurrentInfo.state -eq 'enabled') { $true } else { $false }
32+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/Email' -tenantid $Tenant
33+
$StateIsCorrect = ($CurrentState.state -eq 'disabled')
3434

3535
If ($Settings.remediate -eq $true) {
36-
if ($State) {
37-
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'Email' -Enabled $false
38-
} else {
36+
if ($StateIsCorrect -eq $true) {
3937
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Email authentication method is already disabled.' -sev Info
38+
} else {
39+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'Email' -Enabled $false
4040
}
4141
}
4242

4343
if ($Settings.alert -eq $true) {
44-
if ($State) {
44+
if ($StateIsCorrect -eq $true) {
4545
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Email authentication method is enabled' -sev Alert
4646
} else {
4747
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Email authentication method is not enabled' -sev Info
4848
}
4949
}
5050

5151
if ($Settings.report -eq $true) {
52-
Add-CIPPBPAField -FieldName 'DisableEmail' -FieldValue $State -StoreAs bool -Tenant $tenant
52+
Add-CIPPBPAField -FieldName 'DisableEmail' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5353
}
5454
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardDisableSMS.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@ function Invoke-CIPPStandardDisableSMS {
2929
param($Tenant, $Settings)
3030
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'DisableSMS'
3131

32-
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/SMS' -tenantid $Tenant
33-
$State = if ($CurrentInfo.state -eq 'enabled') { $true } else { $false }
32+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/SMS' -tenantid $Tenant
33+
$StateIsCorrect = ($CurrentState.state -eq 'disabled')
3434

3535
If ($Settings.remediate -eq $true) {
36-
if ($State) {
37-
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'SMS' -Enabled $false
38-
} else {
36+
if ($StateIsCorrect -eq $true) {
3937
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SMS authentication method is already disabled.' -sev Info
38+
} else {
39+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'SMS' -Enabled $false
4040
}
4141
}
4242

4343
if ($Settings.alert -eq $true) {
44-
if ($State) {
44+
if ($StateIsCorrect -eq $true) {
4545
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SMS authentication method is enabled' -sev Alert
4646
} else {
4747
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SMS authentication method is not enabled' -sev Info
4848
}
4949
}
5050

5151
if ($Settings.report -eq $true) {
52-
Add-CIPPBPAField -FieldName 'DisableSMS' -FieldValue $State -StoreAs bool -Tenant $tenant
52+
Add-CIPPBPAField -FieldName 'DisableSMS' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5353
}
5454
}

0 commit comments

Comments
 (0)