Skip to content

Commit b147273

Browse files
Merge branch 'dev' of https://github.com/KelvinTegelaar/CIPP-API into dev
2 parents e9fed84 + 7ca41ce commit b147273

File tree

9 files changed

+113
-62
lines changed

9 files changed

+113
-62
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function Get-ExoOnlineStringBytes {
2+
param([string]$SizeString)
3+
4+
# This exists because various exo cmdlets like to return a human readable string like "3.322 KB (3,402 bytes)" but not the raw bytes value
5+
6+
if ($SizeString -match '\(([0-9,]+) bytes\)') {
7+
return [int]($Matches[1] -replace ',','')
8+
}
9+
10+
return 0
11+
}

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,31 @@ function Invoke-ExecPerUserMFA {
66
.ROLE
77
Identity.User.ReadWrite
88
#>
9-
Param(
10-
$Request,
11-
$TriggerMetadata
12-
)
9+
Param($Request, $TriggerMetadata)
10+
11+
$APIName = $Request.Params.CIPPEndpoint
12+
$Headers = $Request.Headers
13+
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
14+
1315

1416
$Request = @{
15-
userId = $Request.Body.userId
16-
TenantFilter = $Request.Body.TenantFilter
17-
State = $Request.Body.State.value ? $Request.Body.State.value : $Request.Body.State
18-
Headers = $Request.Headers
17+
userId = $Request.Body.userId
18+
TenantFilter = $Request.Body.tenantFilter
19+
State = $Request.Body.State.value ? $Request.Body.State.value : $Request.Body.State
20+
Headers = $Headers
21+
APIName = $APIName
1922
}
20-
$Result = Set-CIPPPerUserMFA @Request
21-
$Body = @{
22-
Results = @($Result)
23+
try {
24+
$Result = Set-CIPPPerUserMFA @Request
25+
$StatusCode = [HttpStatusCode]::OK
26+
} catch {
27+
$Result = $_.Exception.Message
28+
$StatusCode = [HttpStatusCode]::InternalServerError
2329
}
30+
31+
# Associate values to output bindings by calling 'Push-OutputBinding'.
2432
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
25-
StatusCode = [HttpStatusCode]::OK
26-
Body = $Body
33+
StatusCode = $StatusCode
34+
Body = @{ 'Results' = @($Result) }
2735
})
2836
}

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@ function Invoke-ExecPerUserMFAAllUsers {
66
.ROLE
77
Identity.User.ReadWrite
88
#>
9-
Param(
10-
$Request,
11-
$TriggerMetadata
12-
)
13-
$TenantFilter = $request.query.TenantFilter
9+
Param($Request, $TriggerMetadata)
10+
11+
$APIName = $Request.Params.CIPPEndpoint
12+
$Headers = $Request.Headers
13+
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
14+
15+
# XXX Seems to be an unused endpoint? - Bobby
16+
17+
$TenantFilter = $request.Query.tenantFilter
1418
$Users = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/users' -tenantid $TenantFilter
1519
$Request = @{
16-
userId = $Users.id
17-
TenantFilter = $tenantfilter
18-
State = $Request.query.State
19-
Headers = $Request.Headers
20+
userId = $Users.id
21+
TenantFilter = $TenantFilter
22+
State = $Request.Query.State
23+
Headers = $Request.Headers
24+
APIName = $APIName
2025
}
2126
$Result = Set-CIPPPerUserMFA @Request
2227
$Body = @{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function Invoke-ListUserMailboxDetails {
164164
$ProhibitSendQuotaString = $MailboxDetailedRequest.ProhibitSendQuota -split ' '
165165
$ProhibitSendReceiveQuotaString = $MailboxDetailedRequest.ProhibitSendReceiveQuota -split ' '
166166
$TotalItemSizeString = $StatsRequest.TotalItemSize -split ' '
167-
$TotalArchiveItemSizeString = $ArchiveSizeRequest.TotalItemSize -split ' '
167+
$TotalArchiveItemSizeString = Get-ExoOnlineStringBytes -SizeString $ArchiveSizeRequest.TotalItemSize.Value
168168

169169
$ProhibitSendQuota = try { [math]::Round([float]($ProhibitSendQuotaString[0]), 2) } catch { 0 }
170170
$ProhibitSendReceiveQuota = try { [math]::Round([float]($ProhibitSendReceiveQuotaString[0]), 2) } catch { 0 }

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ListStandardsCompare.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ Function Invoke-ListStandardsCompare {
2525
} else {
2626
$_.Value = [string]$_.Value
2727
}
28-
$object | Add-Member -MemberType NoteProperty -Name $_.Name.Replace('standards_', 'standards.') -Value $_.Value -Force
28+
29+
$Key = $_.Name.replace('standards_', 'standards.')
30+
$Key = $Key.replace('IntuneTemplate_', 'IntuneTemplate.')
31+
$Key = $Key -replace '__', '-'
32+
33+
$object | Add-Member -MemberType NoteProperty -Name $Key -Value $_.Value -Force
2934
$object.PSObject.Properties.Remove($_.Name)
3035
}
31-
3236
}
3337
}
3438

Modules/CIPPCore/Public/Set-CIPPMailboxLocale.ps1

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,32 @@ function Set-CippMailboxLocale {
22
[CmdletBinding()]
33
param (
44
$Headers,
5-
$locale,
6-
$username,
5+
$Locale,
6+
$Username,
77
$APIName = 'Mailbox Locale',
88
$TenantFilter
99
)
1010

1111
try {
12+
# Validate the locale. Also if the locale is not valid, it will throw an exception, not wasting a request.
13+
if ([System.Globalization.CultureInfo]::GetCultureInfo($Locale).IsNeutralCulture) {
14+
throw "$Locale is not a valid Locale. Neutral cultures are not supported."
15+
}
16+
1217
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-MailboxRegionalConfiguration' -cmdParams @{
13-
Identity = $username
14-
Language = $locale
18+
Identity = $Username
19+
Language = $Locale
1520
LocalizeDefaultFolderName = $true
21+
DateFormat = $null
22+
TimeFormat = $null
1623
} -Anchor $username
17-
$Result = "Set locale for $($username) to a $locale"
18-
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev 'Info' -tenant $TenantFilter
24+
$Result = "Set locale for $($Username) to $Locale"
25+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Info -tenant $TenantFilter
1926
return $Result
2027
} catch {
2128
$ErrorMessage = Get-CippException -Exception $_
22-
$Result = "Could not set locale for $($username). Error: $($ErrorMessage.NormalizedError)"
23-
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
29+
$Result = "Failed to set locale for $($Username). Error: $($ErrorMessage.NormalizedError)"
30+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Error -tenant $TenantFilter -LogData $ErrorMessage
2431
throw $Result
2532
}
2633
}

Modules/CIPPCore/Public/Set-CIPPPerUserMFA.ps1

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ function Set-CIPPPerUserMFA {
2929
[string[]]$userId,
3030
[ValidateSet('enabled', 'disabled', 'enforced')]
3131
$State = 'enabled',
32-
[string]$Headers = 'CIPP'
32+
$Headers,
33+
$APIName = 'Set-CIPPPerUserMFA'
3334
)
35+
3436
try {
3537
$int = 0
3638
$Body = @{
@@ -48,8 +50,7 @@ function Set-CIPPPerUserMFA {
4850
}
4951
}
5052

51-
$Requests = New-GraphBulkRequest -tenantid $tenantfilter -scope 'https://graph.microsoft.com/.default' -Requests @($Requests) -asapp $true
52-
53+
$Requests = New-GraphBulkRequest -tenantid $TenantFilter -scope 'https://graph.microsoft.com/.default' -Requests @($Requests) -asapp $true
5354
"Successfully set Per user MFA State for $userId"
5455

5556
$Users = foreach ($id in $userId) {
@@ -61,10 +62,11 @@ function Set-CIPPPerUserMFA {
6162
}
6263
}
6364
Set-CIPPUserSchemaProperties -TenantFilter $TenantFilter -Users $Users
64-
Write-LogMessage -headers $Headers -API 'Set-CIPPPerUserMFA' -message "Successfully set Per user MFA State to $State for $id" -Sev 'Info' -tenant $TenantFilter
65+
Write-LogMessage -headers $Headers -API $APIName -message "Successfully set Per user MFA State to $State for $id" -Sev Info -tenant $TenantFilter
6566
} catch {
6667
$ErrorMessage = Get-CippException -Exception $_
67-
"Failed to set MFA State for $id. Error: $($ErrorMessage.NormalizedError)"
68-
Write-LogMessage -headers $Headers -API 'Set-CIPPPerUserMFA' -message "Failed to set MFA State to $State for $id. Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
68+
$Result = "Failed to set MFA State to $State for $id. Error: $($ErrorMessage.NormalizedError)"
69+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Error -tenant $TenantFilter -LogData $ErrorMessage
70+
throw $Result
6971
}
7072
}

Modules/CIPPCore/Public/Set-CIPPStandardsCompareField.ps1

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ function Set-CIPPStandardsCompareField {
66
)
77
$Table = Get-CippTable -tablename 'CippStandardsReports'
88
$TenantName = Get-Tenants | Where-Object -Property defaultDomainName -EQ $Tenant
9-
#if the fieldname does not contain standards. prepend it.
9+
10+
# Sanitize invalid c#/xml characters for Azure Tables
1011
$FieldName = $FieldName.replace('standards.', 'standards_')
12+
$FieldName = $FieldName.replace('IntuneTemplate.', 'IntuneTemplate_')
13+
$FieldName = $FieldName -replace '-', '__'
14+
1115
if ($FieldValue -is [System.Boolean]) {
1216
$fieldValue = [bool]$FieldValue
1317
} elseif ($FieldValue -is [string]) {
@@ -18,24 +22,28 @@ function Set-CIPPStandardsCompareField {
1822
}
1923

2024
$Existing = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'StandardReport' and RowKey eq '$($TenantName.defaultDomainName)'"
21-
if ($Existing) {
22-
$Existing = $Existing | Select-Object * -ExcludeProperty ETag, TimeStamp | ConvertTo-Json -Depth 10 -Compress | ConvertFrom-Json -AsHashtable
23-
$Existing[$FieldName] = $FieldValue
24-
$Existing['LastRefresh'] = [string]$(Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z')
25-
$Existing = [PSCustomObject]$Existing
25+
try {
26+
if ($Existing) {
27+
$Existing = $Existing | Select-Object * -ExcludeProperty ETag, TimeStamp | ConvertTo-Json -Depth 10 -Compress | ConvertFrom-Json -AsHashtable
28+
$Existing[$FieldName] = $FieldValue
29+
$Existing['LastRefresh'] = [string]$(Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z')
30+
$Existing = [PSCustomObject]$Existing
2631

27-
Add-CIPPAzDataTableEntity @Table -Entity $Existing -Force
28-
} else {
29-
$Result = @{
30-
tenantFilter = "$($TenantName.defaultDomainName)"
31-
GUID = "$($TenantName.customerId)"
32-
RowKey = "$($TenantName.defaultDomainName)"
33-
PartitionKey = 'StandardReport'
34-
LastRefresh = [string]$(Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z')
35-
}
36-
$Result[$FieldName] = $FieldValue
37-
Add-CIPPAzDataTableEntity @Table -Entity $Result -Force
32+
Add-CIPPAzDataTableEntity @Table -Entity $Existing -Force
33+
} else {
34+
$Result = @{
35+
tenantFilter = "$($TenantName.defaultDomainName)"
36+
GUID = "$($TenantName.customerId)"
37+
RowKey = "$($TenantName.defaultDomainName)"
38+
PartitionKey = 'StandardReport'
39+
LastRefresh = [string]$(Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z')
40+
}
41+
$Result[$FieldName] = $FieldValue
42+
Add-CIPPAzDataTableEntity @Table -Entity $Result -Force
3843

44+
}
45+
Write-Information "Adding $FieldName to StandardCompare for $Tenant. content is $FieldValue"
46+
} catch {
47+
Write-Warning "Failed to add $FieldName to StandardCompare for $Tenant. content is $FieldValue - $($_.Exception.Message)"
3948
}
40-
Write-Information "Adding $FieldName to StandardCompare for $Tenant. content is $FieldValue"
4149
}

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ function Invoke-CIPPStandardIntuneTemplate {
8484
assignTo = $Template.AssignTo
8585
excludeGroup = $Template.excludeGroup
8686
remediate = $Template.remediate
87+
alert = $Template.alert
88+
report = $Template.report
8789
existingPolicyId = $ExistingPolicy.id
8890
templateId = $Template.TemplateList.value
8991
customGroup = $Template.customGroup
@@ -100,6 +102,8 @@ function Invoke-CIPPStandardIntuneTemplate {
100102
assignTo = $Template.AssignTo
101103
excludeGroup = $Template.excludeGroup
102104
remediate = $Template.remediate
105+
alert = $Template.alert
106+
report = $Template.report
103107
existingPolicyId = $ExistingPolicy.id
104108
templateId = $Template.TemplateList.value
105109
customGroup = $Template.customGroup
@@ -122,8 +126,9 @@ function Invoke-CIPPStandardIntuneTemplate {
122126

123127
}
124128

125-
if ($Settings.alert) {
126-
foreach ($Template in $CompareList) {
129+
if ($true -in $Settings.alert) {
130+
foreach ($Template in $CompareList | Where-Object -Property alert -EQ $true) {
131+
Write-Host "working on template alert: $($Template.displayname)"
127132
$AlertObj = $Template | Select-Object -Property displayname, description, compare, assignTo, excludeGroup, existingPolicyId
128133
if ($Template.compare) {
129134
Write-StandardsAlert -message "Template $($Template.displayname) does not match the expected configuration." -object $AlertObj -tenant $Tenant -standardName 'IntuneTemplate' -standardId $Settings.templateId
@@ -139,13 +144,14 @@ function Invoke-CIPPStandardIntuneTemplate {
139144
}
140145
}
141146

142-
if ($Settings.report) {
143-
foreach ($Template in $CompareList) {
147+
if ($true -in $Settings.report) {
148+
foreach ($Template in $CompareList | Where-Object -Property report -EQ $true) {
149+
Write-Host "working on template report: $($Template.displayname)"
144150
$id = $Template.templateId
145151
$CompareObj = $Template.compare
146152
$state = $CompareObj ? $CompareObj : $true
147153
Set-CIPPStandardsCompareField -FieldName "standards.IntuneTemplate.$id" -FieldValue $state -TenantFilter $Tenant
148154
}
149-
Add-CIPPBPAField -FieldName "policy-$id" -FieldValue $Compare -StoreAs bool -Tenant $tenant
155+
#Add-CIPPBPAField -FieldName "policy-$id" -FieldValue $Compare -StoreAs bool -Tenant $tenant
150156
}
151157
}

0 commit comments

Comments
 (0)