Skip to content

Commit 98f7f61

Browse files
Merge pull request KelvinTegelaar#1231 from KelvinTegelaar/dev
Dev
2 parents 17f65df + 3533643 commit 98f7f61

File tree

9 files changed

+55
-28
lines changed

9 files changed

+55
-28
lines changed

Diff for: Modules/CIPPCore/Public/AuditLogs/Get-CippAuditLogSearchResults.ps1

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function Get-CippAuditLogSearchResults {
2121
process {
2222
$GraphRequest = @{
2323
Uri = ('https://graph.microsoft.com/beta/security/auditLog/queries/{0}/records?$top=999&$count=true' -f $QueryId)
24-
Method = 'GET'
2524
AsApp = $true
2625
tenantid = $TenantFilter
2726
}

Diff for: Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-UpdateTenants.ps1

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ function Push-UpdateTenants {
66
Param($Item)
77
$QueueReference = 'UpdateTenants'
88
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -ne 'Completed' -and $_.Status -ne 'Failed' }
9-
if ($RunningQueue) {
10-
Write-Host 'Update Tenants already running'
11-
return
12-
}
9+
1310
$Queue = New-CippQueueEntry -Name 'Update Tenants' -Reference $QueueReference -TotalTasks 1
1411
try {
1512
$QueueTask = @{
@@ -30,4 +27,4 @@ function Push-UpdateTenants {
3027
$QueueTask.Status = 'Failed'
3128
Set-CippQueueTask @QueueTask
3229
}
33-
}
30+
}

Diff for: Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/Autopilot/Invoke-ExecAssignAPDevice.ps1

+19-8
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,35 @@ Function Invoke-ExecAssignAPDevice {
1010
[CmdletBinding()]
1111
param($Request, $TriggerMetadata)
1212
$APIName = $TriggerMetadata.FunctionName
13-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
14-
$tenantfilter = $Request.Body.TenantFilter
13+
$User = $request.headers.'x-ms-client-principal'
14+
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'
15+
$TenantFilter = $Request.body.tenantFilter
16+
17+
1518
try {
19+
$UserObject = $Request.body.user.addedFields
20+
$DeviceObject = $Request.body.device
21+
$SerialNumber = $Request.body.serialNumber
1622
$body = @{
17-
UserPrincipalName = $Request.body.UserPrincipalName
18-
addressableUserName = $Request.body.addressableUserName
23+
userPrincipalName = $UserObject.userPrincipalName
24+
addressableUserName = $UserObject.addressableUserName
1925
} | ConvertTo-Json
20-
New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeviceIdentities/$($request.body.Device)/UpdateDeviceProperties" -tenantid $TenantFilter -body $body -method POST
21-
$Results = "Successfully assigned device to $($Request.body.UserPrincipalName) for $($tenantfilter)"
26+
New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeviceIdentities/$($DeviceObject)/UpdateDeviceProperties" -tenantid $TenantFilter -body $body -method POST | Out-Null
27+
Write-LogMessage -user $User -API $APINAME -message "Successfully assigned device: $DeviceObject with Serial: $SerialNumber to $($UserObject.userPrincipalName) for $($TenantFilter)" -Sev Info
28+
$Results = "Successfully assigned device: $DeviceObject with Serial: $SerialNumber to $($UserObject.userPrincipalName) for $($TenantFilter)"
29+
$StatusCode = [HttpStatusCode]::OK
2230
} catch {
23-
$Results = "Could not $($Request.body.UserPrincipalName) to $($Request.body.device) for $($tenantfilter) Error: $($_.Exception.Message)"
31+
$ErrorMessage = Get-CippException -Exception $_
32+
Write-LogMessage -user $User -API $APINAME -message "Could not assign $($UserObject.userPrincipalName) to $($DeviceObject) for $($TenantFilter) Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
33+
$Results = "Could not assign $($UserObject.userPrincipalName) to $($DeviceObject) for $($TenantFilter) Error: $($ErrorMessage.NormalizedError)"
34+
$StatusCode = [HttpStatusCode]::BadRequest
2435
}
2536

2637
$Results = [pscustomobject]@{'Results' = "$results" }
2738

2839
# Associate values to output bindings by calling 'Push-OutputBinding'.
2940
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
30-
StatusCode = [HttpStatusCode]::OK
41+
StatusCode = $StatusCode
3142
Body = $Results
3243
})
3344

Diff for: Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ExecJITAdmin.ps1

+8-5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Function Invoke-ExecJITAdmin {
9292
Start-Sleep -Seconds 1
9393
}
9494

95+
#Region TAP creation
9596
if ($Request.Body.UseTAP) {
9697
try {
9798
if ($Start -gt (Get-Date)) {
@@ -102,19 +103,20 @@ Function Invoke-ExecJITAdmin {
102103
} else {
103104
$TapBody = '{}'
104105
}
105-
Write-Information "https://graph.microsoft.com/beta/users/$Username/authentication/temporaryAccessPassMethods"
106-
# Retry creating the TAP up to 5 times, since it can fail due to the user not being fully created yet
106+
# Write-Information "https://graph.microsoft.com/beta/users/$Username/authentication/temporaryAccessPassMethods"
107+
# Retry creating the TAP up to 10 times, since it can fail due to the user not being fully created yet. Sometimes it takes 2 reties, sometimes it takes 8+. Very annoying. -Bobby
107108
$Retries = 0
109+
$MAX_TAP_RETRIES = 10
108110
do {
109111
try {
110112
$TapRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($Username)/authentication/temporaryAccessPassMethods" -tenantid $TenantFilter -type POST -body $TapBody
111113
} catch {
112114
Start-Sleep -Seconds 2
113-
Write-Information 'ERROR: Failed to create TAP, retrying'
114-
Write-Information ( ConvertTo-Json -Depth 5 -InputObject (Get-CippException -Exception $_))
115+
Write-Information "ERROR: Run $Retries of $MAX_TAP_RETRIES : Failed to create TAP, retrying"
116+
# Write-Information ( ConvertTo-Json -Depth 5 -InputObject (Get-CippException -Exception $_))
115117
}
116118
$Retries++
117-
} while ( $null -eq $TapRequest.temporaryAccessPass -and $Retries -le 5 )
119+
} while ( $null -eq $TapRequest.temporaryAccessPass -and $Retries -le $MAX_TAP_RETRIES )
118120

119121
$TempPass = $TapRequest.temporaryAccessPass
120122
$PasswordExpiration = $TapRequest.LifetimeInMinutes
@@ -135,6 +137,7 @@ Function Invoke-ExecJITAdmin {
135137
}
136138
}
137139
}
140+
#EndRegion TAP creation
138141

139142
$Parameters = @{
140143
TenantFilter = $TenantFilter

Diff for: Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Tenant/Invoke-ListTenants.ps1

+14-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,20 @@ Function Invoke-ListTenants {
4545
return
4646
}
4747
if ($Request.Query.TriggerRefresh) {
48-
Get-Tenants -IncludeAll -TriggerRefresh
48+
if ($Request.Query.TenantFilter -and $Request.Query.TenantFilter -ne 'AllTenants') {
49+
Get-Tenants -TriggerRefresh -TenantFilter $Request.Query.TenantFilter
50+
} else {
51+
$InputObject = [PSCustomObject]@{
52+
Batch = @(
53+
@{
54+
FunctionName = 'UpdateTenants'
55+
}
56+
)
57+
OrchestratorName = 'UpdateTenants'
58+
SkipLog = $true
59+
}
60+
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5)
61+
}
4962
}
5063
try {
5164
$tenantfilter = $Request.Query.TenantFilter

Diff for: Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/GDAP/Invoke-ExecDeleteGDAPRoleMapping.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Function Invoke-ExecDeleteGDAPRoleMapping {
1414
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1515
$Table = Get-CIPPTable -TableName 'GDAPRoles'
1616

17-
Write-Host $Table
17+
$GroupId = $Request.Query.GroupId ?? $Request.Body.GroupId
1818
try {
19-
$Filter = "PartitionKey eq 'Roles' and RowKey eq '{0}'" -f $Request.Query.GroupId
19+
$Filter = "PartitionKey eq 'Roles' and RowKey eq '{0}'" -f $GroupId
2020
$Entity = Get-CIPPAzDataTableEntity @Table -Filter $Filter
2121
Remove-AzDataTableEntity -Force @Table -Entity $Entity
2222
$Results = [pscustomobject]@{'Results' = 'Success. GDAP relationship mapping deleted' }
23-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "GDAP relationship mapping deleted for $($Request.Query.GroupId)" -Sev 'Info'
23+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "GDAP relationship mapping deleted for $($GroupId)" -Sev 'Info'
2424

2525
} catch {
2626
$Results = [pscustomobject]@{'Results' = "Failed. $($_.Exception.Message)" }

Diff for: Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-listStandardTemplates.ps1

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ Function Invoke-listStandardTemplates {
1010
[CmdletBinding()]
1111
param($Request, $TriggerMetadata)
1212

13-
$APIName = $TriggerMetadata.FunctionName
14-
1513
$Table = Get-CippTable -tablename 'templates'
1614
$Filter = "PartitionKey eq 'StandardsTemplateV2'"
1715
$Templates = (Get-CIPPAzDataTableEntity @Table -Filter $Filter) | ForEach-Object {
18-
$data = $_.JSON | ConvertFrom-Json -Depth 100
16+
$data = $_.JSON | ConvertFrom-Json -Depth 100 -ErrorAction SilentlyContinue
1917
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $_.GUID -Force
18+
if ($data.excludedTenants) { $data.excludedTenants = @($data.excludedTenants) }
2019
$data
2120
} | Sort-Object -Property templateName
2221

Diff for: Modules/CIPPCore/Public/GraphHelper/New-GraphGetRequest.ps1

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ function New-GraphGetRequest {
1717
[switch]$CountOnly,
1818
[switch]$IncludeResponseHeaders
1919
)
20-
$IsAuthorised = Get-AuthorisedRequest -Uri $uri -TenantID $tenantid
20+
21+
if ($NoAuthCheck -eq $false) {
22+
$IsAuthorised = Get-AuthorisedRequest -Uri $uri -TenantID $tenantid
23+
} else {
24+
$IsAuthorised = $true
25+
}
2126

2227
if ($NoAuthCheck -eq $true -or $IsAuthorised) {
2328
if ($scope -eq 'ExchangeOnline') {

Diff for: version_latest.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.0.3
1+
7.0.4

0 commit comments

Comments
 (0)