Skip to content

Commit d8121a7

Browse files
authored
Merge pull request KelvinTegelaar#212 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents c355a54 + ca3b627 commit d8121a7

8 files changed

Lines changed: 76 additions & 52 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecListBackup.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ Function Invoke-ExecListBackup {
1010
[CmdletBinding()]
1111
param($Request, $TriggerMetadata)
1212

13-
$Result = Get-CIPPBackup -type $Request.body.Type -TenantFilter $Request.body.TenantFilter
13+
$Result = Get-CIPPBackup -type $Request.query.Type -TenantFilter $Request.query.TenantFilter
14+
if ($request.query.NameOnly) {
15+
$Result = $Result | Select-Object RowKey, timestamp
16+
}
1417
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API 'Alerts' -message $request.body.text -Sev $request.body.Severity
1518
# Associate values to output bindings by calling 'Push-OutputBinding'.
1619
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ Function Invoke-AddDefenderDeployment {
3333
allowPartnerToCollectIOSPersonalApplicationMetadata = [bool]$Compliance.ConnectIosCompliance
3434
androidMobileApplicationManagementEnabled = [bool]$Compliance.ConnectAndroidCompliance
3535
iosMobileApplicationManagementEnabled = [bool]$Compliance.appSync
36-
microsoftDefenderForEndpointAttachEnabled = [bool]$compliance.AllowMEMEnforceCompliance
36+
microsoftDefenderForEndpointAttachEnabled = [bool]$true
3737
} | ConvertTo-Json -Compress
38-
$SettingsRequest = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/mobileThreatDefenseConnectors/' -tenantid $tenant -type POST -body $SettingsObj
38+
$SettingsRequest = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/mobileThreatDefenseConnectors/' -tenantid $tenant -type POST -body $SettingsObj -AsApp $true
3939
"$($Tenant): Successfully set Defender Compliance and Reporting settings"
4040

4141
$Settings = switch ($PolicySettings) {
@@ -79,8 +79,7 @@ Function Invoke-AddDefenderDeployment {
7979
Write-Host ($CheckExististing | ConvertTo-Json)
8080
if ('Default AV Policy' -in $CheckExististing.Name) {
8181
"$($Tenant): AV Policy already exists. Skipping"
82-
}
83-
else {
82+
} else {
8483
$PolBody = ConvertTo-Json -Depth 10 -Compress -InputObject @{
8584
name = 'Default AV Policy'
8685
description = ''
@@ -138,8 +137,7 @@ Function Invoke-AddDefenderDeployment {
138137
$CheckExististingASR = New-GraphGETRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/configurationPolicies' -tenantid $tenant
139138
if ('ASR Default rules' -in $CheckExististingASR.Name) {
140139
"$($Tenant): ASR Policy already exists. Skipping"
141-
}
142-
else {
140+
} else {
143141
Write-Host $ASRbody
144142
$ASRRequest = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/configurationPolicies' -tenantid $tenant -type POST -body $ASRbody
145143
Write-Host ($ASRRequest.id)
@@ -215,9 +213,8 @@ Function Invoke-AddDefenderDeployment {
215213
$CheckExististingEDR = New-GraphGETRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/configurationPolicies' -tenantid $tenant
216214
if ('EDR Configuration' -in $CheckExististingEDR.Name) {
217215
"$($Tenant): EDR Policy already exists. Skipping"
218-
}
219-
else {
220-
$EDRRequest = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/configurationPolicies' -tenantid $tenant -type POST -body $EDRbody
216+
} else {
217+
#$EDRRequest = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/configurationPolicies' -tenantid $tenant -type POST -body $EDRbody
221218
if ($ASR.AssignTo -ne 'none') {
222219
$AssignBody = if ($ASR.AssignTo -ne 'AllDevicesAndUsers') { '{"assignments":[{"id":"","target":{"@odata.type":"#microsoft.graph.' + $($asr.AssignTo) + 'AssignmentTarget"}}]}' } else { '{"assignments":[{"id":"","target":{"@odata.type":"#microsoft.graph.allDevicesAssignmentTarget"}},{"id":"","target":{"@odata.type":"#microsoft.graph.allLicensedUsersAssignmentTarget"}}]}' }
223220
$assign = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/configurationPolicies('$($EDRRequest.id)')/assign" -tenantid $tenant -type POST -body $AssignBody
@@ -226,8 +223,7 @@ Function Invoke-AddDefenderDeployment {
226223
"$($Tenant): Successfully added EDR Settings"
227224
}
228225

229-
}
230-
catch {
226+
} catch {
231227
"Failed to add policy for $($Tenant): $($_.Exception.Message)"
232228
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($Tenant) -message "Failed adding policy $($Displayname). Error: $($_.Exception.Message)" -Sev 'Error'
233229
continue

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Teams-Sharepoint/Invoke-ListSites.ps1

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Function Invoke-ListSites {
2929
} else {
3030
$ParsedRequest = $Result
3131
}
32-
$GraphRequest = $ParsedRequest | Select-Object @{ Name = 'UPN'; Expression = { $_.'Owner Principal Name' } },
32+
$GraphRequest = $ParsedRequest | Select-Object AutoMapUrl, @{ Name = 'UPN'; Expression = { $_.'Owner Principal Name' } },
3333
@{ Name = 'displayName'; Expression = { $_.'Owner Display Name' } },
3434
@{ Name = 'LastActive'; Expression = { $_.'Last Activity Date' } },
3535
@{ Name = 'FileCount'; Expression = { [int]$_.'File Count' } },
@@ -41,14 +41,28 @@ Function Invoke-ListSites {
4141

4242
#Temporary workaround for url as report is broken.
4343
#This API is so stupid its great.
44-
$URLs = (New-GraphGetRequest -uri 'https://graph.microsoft.com/v1.0/sites/getAllSites?$select=SharePointIds' -asapp $true -tenantid $TenantFilter).SharePointIds
45-
44+
$URLs = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/sites/getAllSites?$select=SharePointIds,name,webUrl,displayName,siteCollection' -asapp $true -tenantid $TenantFilter
45+
$int = 0
46+
if ($Type -eq 'SharePointSiteUsage') {
47+
$Requests = foreach ($url in $URLs) {
48+
@{
49+
id = $int++
50+
method = 'GET'
51+
url = "sites/$($url.sharepointIds.siteId)/lists?`$select=id,name,list,parentReference"
52+
}
53+
}
54+
$Requests = (New-GraphBulkRequest -tenantid $TenantFilter -scope 'https://graph.microsoft.com/.default' -Requests @($Requests) -asapp $true).body.value | Where-Object { $_.list.template -eq 'DocumentLibrary' }
55+
}
4656
$GraphRequest = foreach ($site in $GraphRequest) {
47-
$site.URL = ($URLs | Where-Object { $_.siteId -eq $site.SiteId }).siteUrl
57+
$SiteURLs = ($URLs.SharePointIds | Where-Object { $_.siteId -eq $site.SiteId })
58+
$site.URL = $SiteURLs.siteUrl
59+
$ListId = ($Requests | Where-Object { $_.parentReference.siteId -like "*$($SiteURLs.siteId)*" }).id
60+
$site.AutoMapUrl = "tenantId=$($SiteUrls.tenantId)&webId={$($SiteUrls.webId)}&siteid={$($SiteURLs.siteId)}&webUrl=$($SiteURLs.siteUrl)&listId={$($ListId)}"
4861
$site
4962
}
5063

5164
$StatusCode = [HttpStatusCode]::OK
65+
5266
} catch {
5367
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
5468
$StatusCode = [HttpStatusCode]::Forbidden

Modules/CIPPCore/Public/Entrypoints/Invoke-AddTenantAllowBlockList.ps1

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,42 @@ Function Invoke-AddTenantAllowBlockList {
1414
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -message 'Accessed this API' -Sev 'Debug'
1515

1616
$blocklistobj = $Request.body
17-
17+
if ($Request.body.tenantId -eq 'AllTenants') { $Tenants = (Get-Tenants).defaultDomainName } else { $Tenants = @($Request.body.tenantId) }
1818
# Write to the Azure Functions log stream.
1919
Write-Host 'PowerShell HTTP trigger function processed a request.'
20-
try {
21-
$ExoRequest = @{
22-
tenantid = $Request.body.tenantid
23-
cmdlet = 'New-TenantAllowBlockListItems'
24-
cmdParams = @{
25-
Entries = [string[]]$blocklistobj.entries
26-
ListType = [string]$blocklistobj.listType
27-
Notes = [string]$blocklistobj.notes
28-
$blocklistobj.listMethod = [bool]$true
20+
$Results = [System.Collections.Generic.List[string]]::new()
21+
foreach ($Tenant in $Tenants) {
22+
try {
23+
$ExoRequest = @{
24+
tenantid = $Tenant
25+
cmdlet = 'New-TenantAllowBlockListItems'
26+
cmdParams = @{
27+
Entries = [string[]]$blocklistobj.entries
28+
ListType = [string]$blocklistobj.listType
29+
Notes = [string]$blocklistobj.notes
30+
$blocklistobj.listMethod = [bool]$true
31+
}
2932
}
30-
}
3133

32-
if ($blocklistobj.NoExpiration -eq $true) {
33-
$ExoRequest.cmdParams.NoExpiration = $true
34-
}
34+
if ($blocklistobj.NoExpiration -eq $true) {
35+
$ExoRequest.cmdParams.NoExpiration = $true
36+
}
3537

36-
New-ExoRequest @ExoRequest
38+
New-ExoRequest @ExoRequest
3739

38-
$result = "Successfully added $($blocklistobj.Entries) as type $($blocklistobj.ListType) to the $($blocklistobj.listMethod) list"
39-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $Request.body.tenantid -message $result -Sev 'Info'
40-
} catch {
41-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
42-
$result = "Failed to create blocklist. Error: $ErrorMessage"
43-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $Request.body.tenantid -message $result -Sev 'Error'
40+
$results.add("Successfully added $($blocklistobj.Entries) as type $($blocklistobj.ListType) to the $($blocklistobj.listMethod) list for $tenant")
41+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $Tenant -message $result -Sev 'Info'
42+
} catch {
43+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
44+
$results.add("Failed to create blocklist. Error: $ErrorMessage")
45+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $Tenant -message $result -Sev 'Error'
46+
}
4447
}
45-
4648
# Associate values to output bindings by calling 'Push-OutputBinding'.
4749
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
4850
StatusCode = [HttpStatusCode]::OK
4951
Body = @{
50-
'Results' = $result
52+
'Results' = $results
5153
'Request' = $ExoRequest
5254
}
5355
})

Modules/CIPPCore/Public/Get-CIPPBackup.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ function Get-CIPPBackup {
44
[string]$Type,
55
[string]$TenantFilter
66
)
7+
Write-Host "Getting backup for $Type with TenantFilter $TenantFilter"
78
$Table = Get-CippTable -tablename "$($Type)Backup"
89
if ($TenantFilter) {
910
$Filter = "PartitionKey eq '$($Type)Backup' and TenantFilter eq '$($TenantFilter)'"

Modules/CIPPCore/Public/New-CIPPBackup.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ function New-CIPPBackup {
6060
RowKey = $RowKey
6161
TenantFilter = $TenantFilter
6262
}
63-
Write-Host "ScheduledBackupValues: $($ScheduledBackupValues | ConvertTo-Json -Compress -Depth 100)"
64-
Write-Host "Scheduled backup value psproperties: $($ScheduledBackupValues.psobject.Properties.Name)"
65-
foreach ($ScheduledBackup in $ScheduledBackupValues.psobject.Properties.Name) {
66-
$entity[$ScheduledBackup] = New-CIPPBackupTask -Task $ScheduledBackup -TenantFilter $TenantFilter
63+
Write-Host "Scheduled backup value psproperties: $(([pscustomobject]$ScheduledBackupValues).psobject.Properties)"
64+
foreach ($ScheduledBackup in ([pscustomobject]$ScheduledBackupValues).psobject.Properties.Name) {
65+
$BackupResult = New-CIPPBackupTask -Task $ScheduledBackup -TenantFilter $TenantFilter | ConvertTo-Json -Depth 100 -Compress | Out-String
66+
$entity[$ScheduledBackup] = "$BackupResult"
6767
}
6868
$Table = Get-CippTable -tablename 'ScheduledBackup'
6969
try {

Modules/CIPPCore/Public/New-CIPPBackupTask.ps1

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,24 @@ function New-CIPPBackupTask {
77

88
$BackupData = switch ($Task) {
99
'users' {
10-
$BackupData = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/users?$top=999' -tenantid $TenantFilter
10+
Write-Host "Backup users for $TenantFilter"
11+
New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/users?$top=999' -tenantid $TenantFilter
1112
}
1213
'groups' {
13-
$BackupData = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/groups?$top=999' -tenantid $TenantFilter
14+
Write-Host "Backup groups for $TenantFilter"
15+
New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/groups?$top=999' -tenantid $TenantFilter
1416
}
1517
'ca' {
16-
$BackupData = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/conditionalAccess/policies?$top=999' -tenantid $TenantFilter
18+
Write-Host "Backup Conditional Access Policies for $TenantFilter"
19+
New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/conditionalAccess/policies?$top=999' -tenantid $TenantFilter
1720
}
1821
'namedlocations' {
19-
$BackupData = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/conditionalAccess/namedLocations?$top=999' -tenantid $TenantFilter
22+
Write-Host "Backup Named Locations for $TenantFilter"
23+
New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/conditionalAccess/namedLocations?$top=999' -tenantid $TenantFilter
2024
}
2125
'authstrengths' {
22-
$BackupData = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/conditionalAccess/authenticationStrength/policies' -tenantid $TenantFilter
26+
Write-Host "Backup Authentication Strength Policies for $TenantFilter"
27+
New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/conditionalAccess/authenticationStrength/policies' -tenantid $TenantFilter
2328
}
2429
'intuneconfig' {
2530
#alert
@@ -29,17 +34,20 @@ function New-CIPPBackupTask {
2934
'intuneprotection' {}
3035

3136
'CippWebhookAlerts' {
37+
Write-Host "Backup Webhook Alerts for $TenantFilter"
3238
$WebhookTable = Get-CIPPTable -TableName 'WebhookRules'
33-
$BackupData = Get-CIPPAzDataTableEntity @WebhookTable | Where-Object { $TenantFilter -in ($_.Tenants | ConvertFrom-Json).fullvalue.defaultDomainName }
39+
Get-CIPPAzDataTableEntity @WebhookTable | Where-Object { $TenantFilter -in ($_.Tenants | ConvertFrom-Json).fullvalue.defaultDomainName }
3440
}
3541
'CippScriptedAlerts' {
42+
Write-Host "Backup Scripted Alerts for $TenantFilter"
3643
$ScheduledTasks = Get-CIPPTable -TableName 'ScheduledTasks'
37-
$BackupData = Get-CIPPAzDataTableEntity @ScheduledTasks | Where-Object { $_.hidden -eq $true -and $_.command -like 'Get-CippAlert*' -and $TenantFilter -in $_.Tenant }
44+
Get-CIPPAzDataTableEntity @ScheduledTasks | Where-Object { $_.hidden -eq $true -and $_.command -like 'Get-CippAlert*' -and $TenantFilter -in $_.Tenant }
3845
}
3946
'CippStandards' {
47+
Write-Host "Backup Standards for $TenantFilter"
4048
$Table = Get-CippTable -tablename 'standards'
4149
$Filter = "PartitionKey eq 'standards' and RowKey eq '$($TenantFilter)'"
42-
$BackupData = (Get-CIPPAzDataTableEntity @Table -Filter $Filter)
50+
(Get-CIPPAzDataTableEntity @Table -Filter $Filter)
4351
}
4452

4553
}

Scheduler_UserTasks/function.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"bindings": [
33
{
44
"name": "Timer",
5-
"schedule": "0 */15 * * * *",
5+
"schedule": "0 */5 * * * *",
66
"direction": "in",
77
"type": "timerTrigger"
88
},

0 commit comments

Comments
 (0)