Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -18,9 +18,11 @@ Function Invoke-AddTeam {
# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'

$Owners = ($userobj.owner).value
$Owners = ($userobj.owner)
try {

if ($null -eq $Owners) {
throw "You have to add at least one owner to the team"
}
$Owners = $Owners | ForEach-Object {
$OwnerID = "https://graph.microsoft.com/beta/users('$($_)')"
@{
Expand Down
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
41 changes: 41 additions & 0 deletions Modules/CIPPCore/Public/Standards/Convert-SingleStandardObject.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function Convert-SingleStandardObject {
param(
[Parameter(Mandatory = $true)]
$Obj
)

# Ensure we have a PSCustomObject we can modify
$Obj = [pscustomobject]$Obj

# Extract action arrays
$AllActionValues = @()
if ($Obj.PSObject.Properties.Name -contains 'combinedActions') {
$AllActionValues = $Obj.combinedActions
$Obj.PSObject.Properties.Remove('combinedActions') | Out-Null
} elseif ($Obj.PSObject.Properties.Name -contains 'action') {
if ($Obj.action -and $Obj.action.value) {
$AllActionValues = $Obj.action.value
}
$Obj.PSObject.Properties.Remove('action') | Out-Null
}

# Convert to booleans
$Obj | Add-Member -NotePropertyName 'remediate' -NotePropertyValue ($AllActionValues -contains 'Remediate') -Force
$Obj | Add-Member -NotePropertyName 'alert' -NotePropertyValue ($AllActionValues -contains 'warn') -Force
$Obj | Add-Member -NotePropertyName 'report' -NotePropertyValue ($AllActionValues -contains 'Report') -Force

# Flatten "standards" if present
if ($Obj.PSObject.Properties.Name -contains 'standards' -and $Obj.standards) {
foreach ($standardKey in $Obj.standards.PSObject.Properties.Name) {
$NestedStandard = $Obj.standards.$standardKey
if ($NestedStandard) {
foreach ($nsProp in $NestedStandard.PSObject.Properties) {
$Obj | Add-Member -NotePropertyName $nsProp.Name -NotePropertyValue $nsProp.Value -Force
}
}
}
$Obj.PSObject.Properties.Remove('standards') | Out-Null
}

return $Obj
}
49 changes: 4 additions & 45 deletions Modules/CIPPCore/Public/Standards/ConvertTo-CippStandardObject.ps1
Original file line number Diff line number Diff line change
@@ -1,59 +1,18 @@
function ConvertTo-CippStandardObject {

param(
[Parameter(Mandatory = $true)]
$StandardObject
)

# If $StandardObject is an array (like for ConditionalAccessTemplate or IntuneTemplate),
# we need to process each item individually.
# If it's an array of items, process each item
if ($StandardObject -is [System.Collections.IEnumerable] -and -not ($StandardObject -is [string])) {
$ProcessedItems = New-Object System.Collections.ArrayList
foreach ($Item in $StandardObject) {
$ProcessedItems.Add((Convert-SingleStandardObject $Item)) | Out-Null
}
return [System.Collections.ArrayList]$ProcessedItems
return $ProcessedItems
} else {
# Single object scenario
# Single object
return Convert-SingleStandardObject $StandardObject
}
}

function Convert-SingleStandardObject {
param(
[Parameter(Mandatory = $true)]
$Obj
)

$Obj = [pscustomobject]$Obj

$AllActionValues = @()
if ($Obj.PSObject.Properties.Name -contains 'combinedActions') {
$AllActionValues = $Obj.combinedActions
$null = $Obj.PSObject.Properties.Remove('combinedActions')
} elseif ($Obj.PSObject.Properties.Name -contains 'action') {
if ($Obj.action -and $Obj.action.value) {
$AllActionValues = $Obj.action.value
}
$null = $Obj.PSObject.Properties.Remove('action')
}

# Convert actions to booleans
$Obj | Add-Member -NotePropertyName 'remediate' -NotePropertyValue ($AllActionValues -contains 'Remediate') -Force
$Obj | Add-Member -NotePropertyName 'alert' -NotePropertyValue ($AllActionValues -contains 'warn') -Force
$Obj | Add-Member -NotePropertyName 'report' -NotePropertyValue ($AllActionValues -contains 'Report') -Force

# Flatten standards if present
if ($Obj.PSObject.Properties.Name -contains 'standards' -and $Obj.standards) {
foreach ($standardKey in $Obj.standards.PSObject.Properties.Name) {
$NestedStandard = $Obj.standards.$standardKey
if ($NestedStandard) {
foreach ($nsProp in $NestedStandard.PSObject.Properties) {
$Obj | Add-Member -NotePropertyName $nsProp.Name -NotePropertyValue $nsProp.Value -Force
}
}
}
$null = $Obj.PSObject.Properties.Remove('standards')
}

return $Obj
}
Loading