Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from KelvinTegelaar:master #40

Merged
merged 24 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ed9814e
Add better error logging
kris6673 Jan 15, 2025
9203439
Standardize formatting, better error logging and support changing the…
kris6673 Jan 15, 2025
fac5755
remove method
JohnDuprey Jan 15, 2025
8c42cc3
Add $null = to all the places missing it in the $result.Add()'s
kris6673 Jan 15, 2025
ad28496
Fix casing for MustChangePass property
kris6673 Jan 15, 2025
e419c72
Increase retry limit for TAP creation to 10 attempts for improved rel…
kris6673 Jan 15, 2025
b3df695
Remove a few comments and add TAP region
kris6673 Jan 15, 2025
8c0f889
Merge pull request #269 from KelvinTegelaar/dev
JohnDuprey Jan 16, 2025
6576516
adding orchestrator for TriggerRefresh
JohnDuprey Jan 16, 2025
3ce26ec
add a silently continue on formatting templates
KelvinTegelaar Jan 16, 2025
0dc364c
add list standards for exclusions
KelvinTegelaar Jan 16, 2025
f90d85b
Update Invoke-ExecDeleteGDAPRoleMapping.ps1
JohnDuprey Jan 16, 2025
2031d7c
Merge pull request #1228 from JohnDuprey/dev
JohnDuprey Jan 16, 2025
7af2347
FIX: modernize and make it work with the new frontend
kris6673 Jan 16, 2025
2113d5d
Update New-GraphGetRequest.ps1
JohnDuprey Jan 16, 2025
b8398ac
Merge branch 'KelvinTegelaar:dev' into dev
JohnDuprey Jan 16, 2025
bcf3770
Merge pull request #1229 from JohnDuprey/dev
JohnDuprey Jan 16, 2025
a8686b4
Remove temporary
KelvinTegelaar Jan 16, 2025
8e52bcd
version up
KelvinTegelaar Jan 16, 2025
7922032
Merge pull request #1230 from kris6673/user-dropdown-fix
KelvinTegelaar Jan 16, 2025
3533643
Merge pull request #1225 from kris6673/fix-inconsisten-TAP-generation
KelvinTegelaar Jan 16, 2025
98f7f61
Merge pull request #1231 from KelvinTegelaar/dev
KelvinTegelaar Jan 16, 2025
0f4549a
Merge pull request #1224 from kris6673/edit-othermails
KelvinTegelaar Jan 16, 2025
fd6c112
Merge pull request #1232 from KelvinTegelaar/dev
KelvinTegelaar Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function Get-CippAuditLogSearchResults {
process {
$GraphRequest = @{
Uri = ('https://graph.microsoft.com/beta/security/auditLog/queries/{0}/records?$top=999&$count=true' -f $QueryId)
Method = 'GET'
AsApp = $true
tenantid = $TenantFilter
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ function Push-UpdateTenants {
Param($Item)
$QueueReference = 'UpdateTenants'
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -ne 'Completed' -and $_.Status -ne 'Failed' }
if ($RunningQueue) {
Write-Host 'Update Tenants already running'
return
}

$Queue = New-CippQueueEntry -Name 'Update Tenants' -Reference $QueueReference -TotalTasks 1
try {
$QueueTask = @{
Expand All @@ -30,4 +27,4 @@ function Push-UpdateTenants {
$QueueTask.Status = 'Failed'
Set-CippQueueTask @QueueTask
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,35 @@ Function Invoke-ExecAssignAPDevice {
[CmdletBinding()]
param($Request, $TriggerMetadata)
$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$tenantfilter = $Request.Body.TenantFilter
$User = $request.headers.'x-ms-client-principal'
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$TenantFilter = $Request.body.tenantFilter


try {
$UserObject = $Request.body.user.addedFields
$DeviceObject = $Request.body.device
$SerialNumber = $Request.body.serialNumber
$body = @{
UserPrincipalName = $Request.body.UserPrincipalName
addressableUserName = $Request.body.addressableUserName
userPrincipalName = $UserObject.userPrincipalName
addressableUserName = $UserObject.addressableUserName
} | ConvertTo-Json
New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeviceIdentities/$($request.body.Device)/UpdateDeviceProperties" -tenantid $TenantFilter -body $body -method POST
$Results = "Successfully assigned device to $($Request.body.UserPrincipalName) for $($tenantfilter)"
New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeviceIdentities/$($DeviceObject)/UpdateDeviceProperties" -tenantid $TenantFilter -body $body -method POST | Out-Null
Write-LogMessage -user $User -API $APINAME -message "Successfully assigned device: $DeviceObject with Serial: $SerialNumber to $($UserObject.userPrincipalName) for $($TenantFilter)" -Sev Info
$Results = "Successfully assigned device: $DeviceObject with Serial: $SerialNumber to $($UserObject.userPrincipalName) for $($TenantFilter)"
$StatusCode = [HttpStatusCode]::OK
} catch {
$Results = "Could not $($Request.body.UserPrincipalName) to $($Request.body.device) for $($tenantfilter) Error: $($_.Exception.Message)"
$ErrorMessage = Get-CippException -Exception $_
Write-LogMessage -user $User -API $APINAME -message "Could not assign $($UserObject.userPrincipalName) to $($DeviceObject) for $($TenantFilter) Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
$Results = "Could not assign $($UserObject.userPrincipalName) to $($DeviceObject) for $($TenantFilter) Error: $($ErrorMessage.NormalizedError)"
$StatusCode = [HttpStatusCode]::BadRequest
}

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

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

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Function Invoke-ExecJITAdmin {
Start-Sleep -Seconds 1
}

#Region TAP creation
if ($Request.Body.UseTAP) {
try {
if ($Start -gt (Get-Date)) {
Expand All @@ -102,19 +103,20 @@ Function Invoke-ExecJITAdmin {
} else {
$TapBody = '{}'
}
Write-Information "https://graph.microsoft.com/beta/users/$Username/authentication/temporaryAccessPassMethods"
# Retry creating the TAP up to 5 times, since it can fail due to the user not being fully created yet
# Write-Information "https://graph.microsoft.com/beta/users/$Username/authentication/temporaryAccessPassMethods"
# 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
$Retries = 0
$MAX_TAP_RETRIES = 10
do {
try {
$TapRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($Username)/authentication/temporaryAccessPassMethods" -tenantid $TenantFilter -type POST -body $TapBody
} catch {
Start-Sleep -Seconds 2
Write-Information 'ERROR: Failed to create TAP, retrying'
Write-Information ( ConvertTo-Json -Depth 5 -InputObject (Get-CippException -Exception $_))
Write-Information "ERROR: Run $Retries of $MAX_TAP_RETRIES : Failed to create TAP, retrying"
# Write-Information ( ConvertTo-Json -Depth 5 -InputObject (Get-CippException -Exception $_))
}
$Retries++
} while ( $null -eq $TapRequest.temporaryAccessPass -and $Retries -le 5 )
} while ( $null -eq $TapRequest.temporaryAccessPass -and $Retries -le $MAX_TAP_RETRIES )

$TempPass = $TapRequest.temporaryAccessPass
$PasswordExpiration = $TapRequest.LifetimeInMinutes
Expand All @@ -135,6 +137,7 @@ Function Invoke-ExecJITAdmin {
}
}
}
#EndRegion TAP creation

$Parameters = @{
TenantFilter = $TenantFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,20 @@ Function Invoke-ListTenants {
return
}
if ($Request.Query.TriggerRefresh) {
Get-Tenants -IncludeAll -TriggerRefresh
if ($Request.Query.TenantFilter -and $Request.Query.TenantFilter -ne 'AllTenants') {
Get-Tenants -TriggerRefresh -TenantFilter $Request.Query.TenantFilter
} else {
$InputObject = [PSCustomObject]@{
Batch = @(
@{
FunctionName = 'UpdateTenants'
}
)
OrchestratorName = 'UpdateTenants'
SkipLog = $true
}
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5)
}
}
try {
$tenantfilter = $Request.Query.TenantFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Function Invoke-ExecDeleteGDAPRoleMapping {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$Table = Get-CIPPTable -TableName 'GDAPRoles'

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

} catch {
$Results = [pscustomobject]@{'Results' = "Failed. $($_.Exception.Message)" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ Function Invoke-listStandardTemplates {
[CmdletBinding()]
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName

$Table = Get-CippTable -tablename 'templates'
$Filter = "PartitionKey eq 'StandardsTemplateV2'"
$Templates = (Get-CIPPAzDataTableEntity @Table -Filter $Filter) | ForEach-Object {
$data = $_.JSON | ConvertFrom-Json -Depth 100
$data = $_.JSON | ConvertFrom-Json -Depth 100 -ErrorAction SilentlyContinue
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $_.GUID -Force
if ($data.excludedTenants) { $data.excludedTenants = @($data.excludedTenants) }
$data
} | Sort-Object -Property templateName

Expand Down
7 changes: 6 additions & 1 deletion Modules/CIPPCore/Public/GraphHelper/New-GraphGetRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ function New-GraphGetRequest {
[switch]$CountOnly,
[switch]$IncludeResponseHeaders
)
$IsAuthorised = Get-AuthorisedRequest -Uri $uri -TenantID $tenantid

if ($NoAuthCheck -eq $false) {
$IsAuthorised = Get-AuthorisedRequest -Uri $uri -TenantID $tenantid
} else {
$IsAuthorised = $true
}

if ($NoAuthCheck -eq $true -or $IsAuthorised) {
if ($scope -eq 'ExchangeOnline') {
Expand Down
7 changes: 4 additions & 3 deletions Modules/CIPPCore/Public/Set-CIPPUserLicense.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ function Set-CIPPUserLicense {
Write-Host "License body JSON: $LicenseBodyJson"

try {
$LicRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$UserId/assignLicense" -tenantid $TenantFilter -type POST -body $LicenseBodyJson -Verbose
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$UserId/assignLicense" -tenantid $TenantFilter -type POST -body $LicenseBodyJson -Verbose
} catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $TenantFilter -message "Failed to assign the license. Error: $_" -Sev 'Error'
throw "Failed to assign the license. $_"
$ErrorMessage = Get-CippException -Exception $_
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $TenantFilter -message "Failed to assign the license. Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
throw "Failed to assign the license. $($ErrorMessage.NormalizedError)"
}

Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $TenantFilter -message "Assigned licenses to user $UserId. Added: $AddLicenses; Removed: $RemoveLicenses" -Sev 'Info'
Expand Down
2 changes: 1 addition & 1 deletion version_latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.3
7.0.4