Skip to content

Commit 5047c3f

Browse files
authored
Merge pull request #248 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents d4f82b3 + 3c66a35 commit 5047c3f

File tree

7 files changed

+185
-69
lines changed

7 files changed

+185
-69
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using namespace System.Net
2+
3+
Function Invoke-ExecSetMailboxEmailSize {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Exchange.Mailbox.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $Request.Params.CIPPEndpoint
14+
$Headers = $Request.Headers
15+
Write-LogMessage -Headers $User -API $APIName -message 'Accessed this API' -Sev 'Debug'
16+
17+
# Interact with query parameters or the body of the request.
18+
$Tenant = $Request.Body.tenantFilter
19+
$UserPrincipalName = $Request.Body.UPN
20+
$UserID = $Request.Body.id
21+
$MaxSendSize = $Request.Body.maxSendSize
22+
$MaxReceiveSize = $Request.Body.maxReceiveSize
23+
24+
try {
25+
$Params = @{
26+
TenantFilter = $Tenant
27+
APIName = $APIName
28+
Headers = $Headers
29+
UserPrincipalName = $UserPrincipalName
30+
UserID = $UserID
31+
MaxSendSize = $MaxSendSize
32+
MaxReceiveSize = $MaxReceiveSize
33+
}
34+
if ([string]::IsNullOrWhiteSpace($MaxSendSize)) { $Params.Remove('MaxSendSize') }
35+
if ([string]::IsNullOrWhiteSpace($MaxReceiveSize)) { $Params.Remove('MaxReceiveSize') }
36+
$Result = Set-CippMaxEmailSize @Params
37+
$StatusCode = [HttpStatusCode]::OK
38+
} catch {
39+
$Result = "$($_.Exception.Message)"
40+
$StatusCode = [HttpStatusCode]::InternalServerError
41+
}
42+
43+
# Associate values to output bindings by calling 'Push-OutputBinding'.
44+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
45+
StatusCode = $StatusCode
46+
Body = @{ Results = $Result }
47+
})
48+
49+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/MEM/Invoke-ExecDeviceAction.ps1

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,45 @@ Function Invoke-ExecDeviceAction {
1515
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616

1717
# Interact with Body parameters or the body of the request.
18-
18+
$Action = $Request.Body.Action
19+
$DeviceFilter = $Request.Body.GUID
20+
$TenantFilter = $Request.Body.tenantFilter
1921

2022
try {
21-
if ($Request.Body.Action -eq 'setDeviceName') {
22-
$ActionBody = @{ deviceName = $Request.Body.input } | ConvertTo-Json -Compress
23-
}
24-
else {
25-
$ActionBody = $Request.Body | ConvertTo-Json -Compress
23+
switch ($Action) {
24+
'setDeviceName' {
25+
$ActionBody = @{ deviceName = $Request.Body.input } | ConvertTo-Json -Compress
26+
break
27+
}
28+
'users' {
29+
$ActionBody = @{ '@odata.id' = "https://graph.microsoft.com/beta/users('$($Request.Body.user.value)')" } | ConvertTo-Json -Compress
30+
Write-Host "ActionBody: $ActionBody"
31+
break
32+
}
33+
Default { $ActionBody = $Request.Body | ConvertTo-Json -Compress }
2634
}
2735

28-
$cmdparams = @{
29-
Action = $Request.Body.Action
30-
ActionBody = $ActionBody
31-
DeviceFilter = $Request.Body.GUID
32-
TenantFilter = $Request.Body.TenantFilter
33-
Headers = $Request.Headers
34-
APINAME = $APINAME
36+
$cmdParams = @{
37+
Action = $Action
38+
ActionBody = $ActionBody
39+
DeviceFilter = $DeviceFilter
40+
TenantFilter = $TenantFilter
41+
Headers = $Headers
42+
APINAME = $APIName
3543
}
36-
$ActionResult = New-CIPPDeviceAction @cmdparams
44+
$ActionResult = New-CIPPDeviceAction @cmdParams
3745

38-
$body = [pscustomobject]@{'Results' = "$ActionResult" }
46+
$StatusCode = [HttpStatusCode]::OK
47+
$Results = "$ActionResult"
3948

4049
} catch {
41-
$body = [pscustomobject]@{'Results' = "Failed to queue action $action on $DeviceFilter $($_.Exception.Message)" }
50+
$StatusCode = [HttpStatusCode]::InternalServerError
51+
$Results = "$($_.Exception.Message)"
4252
}
4353

4454
# Associate values to output bindings by calling 'Push-OutputBinding'.
4555
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
46-
StatusCode = [HttpStatusCode]::OK
47-
Body = $body
56+
StatusCode = $StatusCode
57+
Body = @{ 'Results' = $Results }
4858
})
49-
5059
}

Modules/CIPPCore/Public/New-CIPPDeviceAction.ps1

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,27 @@ function New-CIPPDeviceAction {
66
$DeviceFilter,
77
$TenantFilter,
88
$Headers,
9-
$APINAME
9+
$APIName
1010
)
1111
try {
12-
if ($action -eq 'delete') {
13-
$null = New-Graphpostrequest -uri "https://graph.microsoft.com/beta/deviceManagement/managedDevices/$DeviceFilter" -type DELETE -tenantid $TenantFilter
14-
Write-LogMessage -headers $Headers -API $APINAME -tenant $TenantFilter -message "Queued $Action on $DeviceFilter" -Sev 'Info'
15-
return "Queued $Action on $DeviceFilter"
12+
if ($Action -eq 'delete') {
13+
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/managedDevices/$DeviceFilter" -type DELETE -tenantid $TenantFilter
14+
} elseif ($Action -eq 'users') {
15+
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/managedDevices('$DeviceFilter')/$($Action)/`$ref" -type POST -tenantid $TenantFilter -body $ActionBody
16+
$regex = "(?<=\(')([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})(?='|\))"
17+
$PrimaryUser = $ActionBody | Select-String -Pattern $regex -AllMatches | Select-Object -ExpandProperty Matches | Select-Object -ExpandProperty Value
18+
$Result = "Changed primary user on device $DeviceFilter to $PrimaryUser"
19+
} else {
20+
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/managedDevices('$DeviceFilter')/$($Action)" -type POST -tenantid $TenantFilter -body $ActionBody
21+
$Result = "Queued $Action on $DeviceFilter"
1622
}
17-
$null = New-Graphpostrequest -uri "https://graph.microsoft.com/beta/deviceManagement/managedDevices('$DeviceFilter')/$($Action)" -type POST -tenantid $TenantFilter -body $ActionBody
18-
Write-LogMessage -headers $Headers -API $APINAME -tenant $TenantFilter -message "Queued $Action on $DeviceFilter" -Sev 'Info'
19-
return "Queued $Action on $DeviceFilter"
23+
24+
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -Sev Info
25+
return $Result
2026
} catch {
2127
$ErrorMessage = Get-CippException -Exception $_
22-
Write-LogMessage -headers $Headers -API $APINAME -tenant $TenantFilter -message "Failed to queue action $Action on $DeviceFilter : $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
23-
return "Failed to queue action $Action on $DeviceFilter $($ErrorMessage.NormalizedError)"
28+
$Result = "Failed to queue action $Action on $DeviceFilter : $($ErrorMessage.NormalizedError)"
29+
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -Sev Error -LogData $ErrorMessage
30+
throw $Result
2431
}
2532
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function Set-CippMaxEmailSize {
2+
[CmdletBinding()]
3+
param (
4+
$Headers,
5+
$TenantFilter,
6+
$APIName = 'Mailbox Max Send/Receive Size',
7+
$UserPrincipalName,
8+
$UserID,
9+
[ValidateRange(1, 150)]
10+
[Int32]$MaxSendSize,
11+
[ValidateRange(1, 150)]
12+
[Int32]$MaxReceiveSize
13+
)
14+
15+
try {
16+
# Id the ID is provided, use it. Otherwise, use the UPN
17+
$Identity = $UserID ?? $UserPrincipalName
18+
if ([string]::IsNullOrWhiteSpace($Identity)) {
19+
$Result = 'No identity provided. Cannot set mailbox email max size.'
20+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Error -tenant $TenantFilter
21+
throw $Result
22+
}
23+
24+
if ($MaxSendSize -eq 0 -and $MaxReceiveSize -eq 0) {
25+
$Result = 'No max send or receive size provided. Cannot set mailbox email max size.'
26+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Error -tenant $TenantFilter
27+
throw $Result
28+
}
29+
30+
$cmdletParams = @{
31+
Identity = $Identity
32+
}
33+
# Set the max send and receive size if they are provided. Convert to bytes
34+
if ($MaxSendSize -gt 0) { $cmdletParams['MaxSendSize'] = $MaxSendSize * 1MB }
35+
if ($MaxReceiveSize -gt 0) { $cmdletParams['MaxReceiveSize'] = $MaxReceiveSize * 1MB }
36+
37+
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-Mailbox' -cmdParams $cmdletParams
38+
39+
# Use UPN for logging if provided
40+
$Identity = $UserPrincipalName ?? $UserID
41+
$Result = "Set mailbox email max size for $($Identity) to "
42+
if ($MaxSendSize -gt 0) { $Result += "Send: $($MaxSendSize)MB " }
43+
if ($MaxReceiveSize -gt 0) { $Result += "Receive: $($MaxReceiveSize)MB" }
44+
45+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Info -tenant $TenantFilter
46+
return $Result
47+
} catch {
48+
$ErrorMessage = Get-CippException -Exception $_
49+
50+
# Use UPN for logging if provided
51+
$Identity = $UserPrincipalName ?? $UserID
52+
$Result = "Failed to set mailbox email max size for $($Identity). Error: $($ErrorMessage)"
53+
54+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Error -tenant $TenantFilter -LogData $ErrorMessage
55+
throw $Result
56+
}
57+
}

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,23 @@ function Invoke-CIPPStandardProfilePhotos {
4242
# true if wanted state is enabled, false if disabled
4343
$DesiredState = $StateValue -eq 'enabled'
4444

45-
<#
46-
HACK This does not work, as the API endpoint is not available via GDAP it seems? It works in the Graph Explorer, but not here.
47-
The error is: "Authorization failed because of missing requirement(s)."
48-
I'm keeping the code here for now, so it's much easier to re-enable if Microsoft makes it possible someday. -Bobby
49-
#>
50-
5145
# Get current Graph policy state
52-
# $Uri = 'https://graph.microsoft.com/beta/admin/people/photoUpdateSettings'
53-
# $CurrentGraphState = New-GraphGetRequest -uri $Uri -tenantid $Tenant
54-
# $UsersCanChangePhotos = if (($CurrentGraphState.allowedRoles -contains 'fe930be7-5e62-47db-91af-98c3a49a38b1' -and $CurrentGraphState.allowedRoles -contains '62e90394-69f5-4237-9190-012177145e10') -or
55-
# $null -ne $CurrentGraphState.allowedRoles) { $false } else { $true }
56-
# $GraphStateCorrect = $UsersCanChangePhotos -eq $DesiredState
46+
$Uri = 'https://graph.microsoft.com/beta/admin/people/photoUpdateSettings'
47+
$CurrentGraphState = New-GraphGetRequest -uri $Uri -tenantid $Tenant
48+
$UsersCanChangePhotos = if ([string]::IsNullOrWhiteSpace($CurrentGraphState.allowedRoles) ) { $true } else { $false }
49+
$GraphStateCorrect = $UsersCanChangePhotos -eq $DesiredState
5750

51+
if ($UsersCanChangePhotos -eq $false -and $DesiredState -eq $false) {
52+
# Check if the correct roles are present
53+
$GraphStateCorrect = $CurrentGraphState.allowedRoles -contains '62e90394-69f5-4237-9190-012177145e10' -and $CurrentGraphState.allowedRoles -contains 'fe930be7-5e62-47db-91af-98c3a49a38b1'
54+
}
5855

5956
# Get current OWA mailbox policy state
6057
$CurrentOWAState = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OwaMailboxPolicy' -cmdParams @{Identity = 'OwaMailboxPolicy-Default' } -Select 'Identity,SetPhotoEnabled'
6158
$OWAStateCorrect = $CurrentOWAState.SetPhotoEnabled -eq $DesiredState
62-
# $CurrentStatesCorrect = $GraphStateCorrect -eq $true -and $OWAStateCorrect -eq $true
63-
$CurrentStatesCorrect = $OWAStateCorrect -eq $true
59+
60+
# Check if both states are correct
61+
$CurrentStatesCorrect = $GraphStateCorrect -eq $true -and $OWAStateCorrect -eq $true
6462

6563
if ($Settings.remediate -eq $true) {
6664
Write-Host 'Time to remediate'
@@ -72,23 +70,23 @@ function Invoke-CIPPStandardProfilePhotos {
7270
Write-Host 'Enabling'
7371
# Enable photo updates
7472
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-OwaMailboxPolicy' -cmdParams @{Identity = $CurrentOWAState.Identity; SetPhotoEnabled = $true } -useSystemMailbox $true
75-
# $null = New-GraphRequest -uri $Uri -tenant $Tenant -type DELETE
73+
$null = New-GraphPostRequest -uri $Uri -tenant $Tenant -type DELETE -AsApp $true
7674
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Set Profile photo settings to $StateValue" -sev Info
7775

7876
} else {
7977
Write-Host 'Disabling'
8078
# Disable photo updates
8179
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-OwaMailboxPolicy' -cmdParams @{Identity = $CurrentOWAState.Identity; SetPhotoEnabled = $false } -useSystemMailbox $true
8280

83-
# $body = @{
84-
# source = 'cloud'
85-
# allowedRoles = @(
86-
# 'fe930be7-5e62-47db-91af-98c3a49a38b1', # Global admin
87-
# '62e90394-69f5-4237-9190-012177145e10' # User admin
88-
# )
89-
# }
90-
# $body = ConvertTo-Json -InputObject $body -Depth 5 -Compress
91-
# $null = New-GraphPostRequest -uri $Uri -tenant $Tenant -body $body -type PATCH -AsApp $true
81+
$body = @{
82+
source = 'cloud'
83+
allowedRoles = @(
84+
'fe930be7-5e62-47db-91af-98c3a49a38b1', # Global admin
85+
'62e90394-69f5-4237-9190-012177145e10' # User admin
86+
)
87+
}
88+
$body = ConvertTo-Json -InputObject $body -Depth 5 -Compress
89+
$null = New-GraphPostRequest -uri $Uri -tenant $Tenant -body $body -type PATCH -AsApp $true
9290
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Set Profile photo settings to $StateValue" -sev Info
9391
}
9492
} catch {
@@ -115,7 +113,10 @@ function Invoke-CIPPStandardProfilePhotos {
115113
if ($CurrentStatesCorrect) {
116114
$FieldValue = $true
117115
} else {
118-
$FieldValue = $CurrentOWAState
116+
$FieldValue = [PSCustomObject]@{
117+
OwaStateCorrect = $OWAStateCorrect
118+
GraphStateCorrect = $GraphStateCorrect
119+
}
119120
}
120121
Set-CIPPStandardsCompareField -FieldName 'standards.ProfilePhotos' -FieldValue $FieldValue -Tenant $Tenant
121122
}

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ function Invoke-CIPPStandardTeamsExternalAccessPolicy {
1515
TAG
1616
ADDEDCOMPONENT
1717
{"type":"switch","name":"standards.TeamsExternalAccessPolicy.EnableFederationAccess","label":"Allow communication from trusted organizations"}
18-
{"type":"switch","name":"standards.TeamsExternalAccessPolicy.EnablePublicCloudAccess","label":"Allow user to communicate with Skype users"}
1918
{"type":"switch","name":"standards.TeamsExternalAccessPolicy.EnableTeamsConsumerAccess","label":"Allow communication with unmanaged Teams accounts"}
2019
IMPACT
2120
Medium Impact
@@ -35,23 +34,20 @@ function Invoke-CIPPStandardTeamsExternalAccessPolicy {
3534

3635
$CurrentState = New-TeamsRequest -TenantFilter $Tenant -Cmdlet 'Get-CsExternalAccessPolicy' -CmdParams @{Identity = 'Global' } | Select-Object *
3736

38-
if ($null -eq $Settings.EnableFederationAccess) { $Settings.EnableFederationAccess = $false }
39-
if ($null -eq $Settings.EnablePublicCloudAccess) { $Settings.EnablePublicCloudAccess = $false }
40-
if ($null -eq $Settings.EnableTeamsConsumerAccess) { $Settings.EnableTeamsConsumerAccess = $false }
37+
$EnableFederationAccess = $Settings.EnableFederationAccess ?? $false
38+
$EnableTeamsConsumerAccess = $Settings.EnableTeamsConsumerAccess ?? $false
4139

42-
$StateIsCorrect = ($CurrentState.EnableFederationAccess -eq $Settings.EnableFederationAccess) -and
43-
($CurrentState.EnablePublicCloudAccess -eq $Settings.EnablePublicCloudAccess) -and
44-
($CurrentState.EnableTeamsConsumerAccess -eq $Settings.EnableTeamsConsumerAccess)
40+
$StateIsCorrect = ($CurrentState.EnableFederationAccess -eq $EnableFederationAccess) -and
41+
($CurrentState.EnableTeamsConsumerAccess -eq $EnableTeamsConsumerAccess)
4542

4643
if ($Settings.remediate -eq $true) {
4744
if ($StateIsCorrect -eq $true) {
4845
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'External Access Policy already set.' -sev Info
4946
} else {
5047
$cmdParams = @{
5148
Identity = 'Global'
52-
EnableFederationAccess = $Settings.EnableFederationAccess
53-
EnablePublicCloudAccess = $Settings.EnablePublicCloudAccess
54-
EnableTeamsConsumerAccess = $Settings.EnableTeamsConsumerAccess
49+
EnableFederationAccess = $EnableFederationAccess
50+
EnableTeamsConsumerAccess = $EnableTeamsConsumerAccess
5551
}
5652

5753
try {
@@ -76,10 +72,10 @@ function Invoke-CIPPStandardTeamsExternalAccessPolicy {
7672
if ($Settings.report -eq $true) {
7773
Add-CIPPBPAField -FieldName 'TeamsExternalAccessPolicy' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $Tenant
7874

79-
if ($StateIsCorrect) {
75+
if ($StateIsCorrect -eq $true) {
8076
$FieldValue = $true
8177
} else {
82-
$FieldValue = $CurrentState | Select-Object EnableFederationAccess, EnablePublicCloudAccess, EnableTeamsConsumerAccess
78+
$FieldValue = $CurrentState | Select-Object EnableFederationAccess, EnableTeamsConsumerAccess
8379
}
8480

8581
Set-CIPPStandardsCompareField -FieldName 'standards.TeamsExternalAccessPolicy' -FieldValue $FieldValue -Tenant $Tenant

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ function Invoke-CIPPStandardTeamsFederationConfiguration {
1515
TAG
1616
ADDEDCOMPONENT
1717
{"type":"switch","name":"standards.TeamsFederationConfiguration.AllowTeamsConsumer","label":"Allow users to communicate with other organizations"}
18-
{"type":"switch","name":"standards.TeamsFederationConfiguration.AllowPublicUsers","label":"Allow users to communicate with Skype Users"}
1918
{"type":"autoComplete","required":true,"multiple":false,"creatable":false,"name":"standards.TeamsFederationConfiguration.DomainControl","label":"Communication Mode","options":[{"label":"Allow all external domains","value":"AllowAllExternal"},{"label":"Block all external domains","value":"BlockAllExternal"},{"label":"Allow specific external domains","value":"AllowSpecificExternal"},{"label":"Block specific external domains","value":"BlockSpecificExternal"}]}
2019
{"type":"textField","name":"standards.TeamsFederationConfiguration.DomainList","label":"Domains, Comma separated","required":false}
2120
IMPACT
@@ -87,7 +86,6 @@ function Invoke-CIPPStandardTeamsFederationConfiguration {
8786
$BlockedDomainsMatches = -not (Compare-Object -ReferenceObject $BlockedDomains -DifferenceObject $CurrentState.BlockedDomains)
8887

8988
$StateIsCorrect = ($CurrentState.AllowTeamsConsumer -eq $Settings.AllowTeamsConsumer) -and
90-
($CurrentState.AllowPublicUsers -eq $Settings.AllowPublicUsers) -and
9189
($CurrentState.AllowFederatedUsers -eq $AllowFederatedUsers) -and
9290
$AllowedDomainsMatches -and
9391
$BlockedDomainsMatches
@@ -99,7 +97,6 @@ function Invoke-CIPPStandardTeamsFederationConfiguration {
9997
$cmdParams = @{
10098
Identity = 'Global'
10199
AllowTeamsConsumer = $Settings.AllowTeamsConsumer
102-
AllowPublicUsers = $Settings.AllowPublicUsers
103100
AllowFederatedUsers = $AllowFederatedUsers
104101
BlockedDomains = $BlockedDomains
105102
}
@@ -134,7 +131,7 @@ function Invoke-CIPPStandardTeamsFederationConfiguration {
134131
if ($StateIsCorrect -eq $true) {
135132
$FieldValue = $true
136133
} else {
137-
$FieldValue = $CurrentState
134+
$FieldValue = $CurrentState | Select-Object AllowTeamsConsumer, AllowFederatedUsers, AllowedDomains, BlockedDomains
138135
}
139136
Set-CIPPStandardsCompareField -FieldName 'standards.TeamsFederationConfiguration' -FieldValue $FieldValue -Tenant $Tenant
140137
}

0 commit comments

Comments
 (0)