Skip to content

Commit a02dc01

Browse files
Merge pull request #1278 from kris6673/autpilot-sync
Fix up Invoke-ExecSyncAPDevices
2 parents a3c59b5 + b8e1db9 commit a02dc01

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ Function Invoke-ExecSyncAPDevices {
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.Query.TenantFilter
13+
$ExecutingUser = $request.headers.'x-ms-client-principal'
14+
$TenantFilter = $Request.Body.tenantFilter ?? $Request.Query.tenantFilter
15+
Write-LogMessage -user $ExecutingUser -API $APINAME -message 'Accessed this API' -Sev Debug
16+
1517
try {
16-
New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotSettings/sync' -tenantid $TenantFilter
18+
$null = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotSettings/sync' -tenantid $TenantFilter
1719
$Results = "Successfully Started Sync for $($TenantFilter)"
20+
Write-LogMessage -user $ExecutingUser -API $APINAME -tenant $TenantFilter -message 'Successfully started Autopilot sync' -Sev Info
21+
$StatusCode = [HttpStatusCode]::OK
1822
} catch {
19-
$Results = "Failed to start sync for $tenantfilter. Did you try syncing in the last 10 minutes?"
23+
$ErrorMessage = Get-CippException -Exception $_
24+
$Results = "Failed to start sync for $TenantFilter. Did you try syncing in the last 10 minutes?"
25+
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
26+
$StatusCode = [HttpStatusCode]::Forbidden
2027
}
2128

22-
$Results = [pscustomobject]@{'Results' = "$results" }
29+
$Results = [pscustomobject]@{'Results' = "$Results" }
2330

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

0 commit comments

Comments
 (0)