Skip to content

Commit

Permalink
Merge pull request #1278 from kris6673/autpilot-sync
Browse files Browse the repository at this point in the history
Fix up Invoke-ExecSyncAPDevices
  • Loading branch information
KelvinTegelaar authored Jan 31, 2025
2 parents a3c59b5 + b8e1db9 commit a02dc01
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-ExecSyncAPDevices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@ Function Invoke-ExecSyncAPDevices {
[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.Query.TenantFilter
$ExecutingUser = $request.headers.'x-ms-client-principal'
$TenantFilter = $Request.Body.tenantFilter ?? $Request.Query.tenantFilter
Write-LogMessage -user $ExecutingUser -API $APINAME -message 'Accessed this API' -Sev Debug

try {
New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotSettings/sync' -tenantid $TenantFilter
$null = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotSettings/sync' -tenantid $TenantFilter
$Results = "Successfully Started Sync for $($TenantFilter)"
Write-LogMessage -user $ExecutingUser -API $APINAME -tenant $TenantFilter -message 'Successfully started Autopilot sync' -Sev Info
$StatusCode = [HttpStatusCode]::OK
} catch {
$Results = "Failed to start sync for $tenantfilter. Did you try syncing in the last 10 minutes?"
$ErrorMessage = Get-CippException -Exception $_
$Results = "Failed to start sync for $TenantFilter. Did you try syncing in the last 10 minutes?"
Write-LogMessage -user $ExecutingUser -API $APINAME -tenant $TenantFilter -message 'Failed to start Autopilot sync. Did you try syncing in the last 10 minutes?' -Sev Error -LogData $ErrorMessage
$StatusCode = [HttpStatusCode]::Forbidden
}

$Results = [pscustomobject]@{'Results' = "$results" }
$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

0 comments on commit a02dc01

Please sign in to comment.