Skip to content

Commit f640974

Browse files
authored
Merge pull request #44 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 5649595 + 2b4e7c4 commit f640974

File tree

6 files changed

+226
-122
lines changed

6 files changed

+226
-122
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ Function Invoke-AddTeam {
1818
# Write to the Azure Functions log stream.
1919
Write-Host 'PowerShell HTTP trigger function processed a request.'
2020

21-
$Owners = ($userobj.owner).value
21+
$Owners = ($userobj.owner)
2222
try {
23-
23+
if ($null -eq $Owners) {
24+
throw "You have to add at least one owner to the team"
25+
}
2426
$Owners = $Owners | ForEach-Object {
2527
$OwnerID = "https://graph.microsoft.com/beta/users('$($_)')"
2628
@{

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function Convert-SingleStandardObject {
2+
param(
3+
[Parameter(Mandatory = $true)]
4+
$Obj
5+
)
6+
7+
# Ensure we have a PSCustomObject we can modify
8+
$Obj = [pscustomobject]$Obj
9+
10+
# Extract action arrays
11+
$AllActionValues = @()
12+
if ($Obj.PSObject.Properties.Name -contains 'combinedActions') {
13+
$AllActionValues = $Obj.combinedActions
14+
$Obj.PSObject.Properties.Remove('combinedActions') | Out-Null
15+
} elseif ($Obj.PSObject.Properties.Name -contains 'action') {
16+
if ($Obj.action -and $Obj.action.value) {
17+
$AllActionValues = $Obj.action.value
18+
}
19+
$Obj.PSObject.Properties.Remove('action') | Out-Null
20+
}
21+
22+
# Convert to booleans
23+
$Obj | Add-Member -NotePropertyName 'remediate' -NotePropertyValue ($AllActionValues -contains 'Remediate') -Force
24+
$Obj | Add-Member -NotePropertyName 'alert' -NotePropertyValue ($AllActionValues -contains 'warn') -Force
25+
$Obj | Add-Member -NotePropertyName 'report' -NotePropertyValue ($AllActionValues -contains 'Report') -Force
26+
27+
# Flatten "standards" if present
28+
if ($Obj.PSObject.Properties.Name -contains 'standards' -and $Obj.standards) {
29+
foreach ($standardKey in $Obj.standards.PSObject.Properties.Name) {
30+
$NestedStandard = $Obj.standards.$standardKey
31+
if ($NestedStandard) {
32+
foreach ($nsProp in $NestedStandard.PSObject.Properties) {
33+
$Obj | Add-Member -NotePropertyName $nsProp.Name -NotePropertyValue $nsProp.Value -Force
34+
}
35+
}
36+
}
37+
$Obj.PSObject.Properties.Remove('standards') | Out-Null
38+
}
39+
40+
return $Obj
41+
}
Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,18 @@
11
function ConvertTo-CippStandardObject {
2+
23
param(
34
[Parameter(Mandatory = $true)]
45
$StandardObject
56
)
6-
7-
# If $StandardObject is an array (like for ConditionalAccessTemplate or IntuneTemplate),
8-
# we need to process each item individually.
7+
# If it's an array of items, process each item
98
if ($StandardObject -is [System.Collections.IEnumerable] -and -not ($StandardObject -is [string])) {
109
$ProcessedItems = New-Object System.Collections.ArrayList
1110
foreach ($Item in $StandardObject) {
1211
$ProcessedItems.Add((Convert-SingleStandardObject $Item)) | Out-Null
1312
}
14-
return [System.Collections.ArrayList]$ProcessedItems
13+
return $ProcessedItems
1514
} else {
16-
# Single object scenario
15+
# Single object
1716
return Convert-SingleStandardObject $StandardObject
1817
}
1918
}
20-
21-
function Convert-SingleStandardObject {
22-
param(
23-
[Parameter(Mandatory = $true)]
24-
$Obj
25-
)
26-
27-
$Obj = [pscustomobject]$Obj
28-
29-
$AllActionValues = @()
30-
if ($Obj.PSObject.Properties.Name -contains 'combinedActions') {
31-
$AllActionValues = $Obj.combinedActions
32-
$null = $Obj.PSObject.Properties.Remove('combinedActions')
33-
} elseif ($Obj.PSObject.Properties.Name -contains 'action') {
34-
if ($Obj.action -and $Obj.action.value) {
35-
$AllActionValues = $Obj.action.value
36-
}
37-
$null = $Obj.PSObject.Properties.Remove('action')
38-
}
39-
40-
# Convert actions to booleans
41-
$Obj | Add-Member -NotePropertyName 'remediate' -NotePropertyValue ($AllActionValues -contains 'Remediate') -Force
42-
$Obj | Add-Member -NotePropertyName 'alert' -NotePropertyValue ($AllActionValues -contains 'warn') -Force
43-
$Obj | Add-Member -NotePropertyName 'report' -NotePropertyValue ($AllActionValues -contains 'Report') -Force
44-
45-
# Flatten standards if present
46-
if ($Obj.PSObject.Properties.Name -contains 'standards' -and $Obj.standards) {
47-
foreach ($standardKey in $Obj.standards.PSObject.Properties.Name) {
48-
$NestedStandard = $Obj.standards.$standardKey
49-
if ($NestedStandard) {
50-
foreach ($nsProp in $NestedStandard.PSObject.Properties) {
51-
$Obj | Add-Member -NotePropertyName $nsProp.Name -NotePropertyValue $nsProp.Value -Force
52-
}
53-
}
54-
}
55-
$null = $Obj.PSObject.Properties.Remove('standards')
56-
}
57-
58-
return $Obj
59-
}

0 commit comments

Comments
 (0)