feat(upstream): port Win32 scripts, quality update policies, sorted JSON
Ported from Micke-K/IntuneManagement 3.10.1.x-3.11.0 (MIT): - Win32 app install/uninstall scripts are exported (#ScriptInfo plus the script files next to the JSON) and recreated on import and copy. - New object type Quality Updates (Policies) (windowsQualityUpdatePolicies); the old type is titled "Quality Updates (Profiles)". - SortJsonProperties setting writes exported JSON with sorted properties for stable diffs; always on for headless export. - EndpointManager.psm1 three-way merged with upstream (page-size flags, app fixes). UI-only changes were not taken.
This commit is contained in:
+154
-1
@@ -200,6 +200,14 @@ function Invoke-InitializeModule
|
||||
Description = "This will add object ID to the export file to support objects with the same name e.g. ObjectName_ObjectId.json"
|
||||
}) "ImportExport"
|
||||
|
||||
Add-SettingsObject (New-Object PSObject -Property @{
|
||||
Title = "Sort Json Properties"
|
||||
Key = "SortJsonProperties"
|
||||
Type = "Boolean"
|
||||
DefaultValue = $false
|
||||
Description = "Write exported JSON with sorted properties so every export has the same property order (clean diffs, stable change tracking)"
|
||||
}) "ImportExport"
|
||||
|
||||
Add-SettingsObject (New-Object PSObject -Property @{
|
||||
Title = "Use Batch API (Preview)"
|
||||
Key = "UseBatchAPI"
|
||||
@@ -4674,7 +4682,14 @@ function Save-GraphObjectToFile
|
||||
{
|
||||
param($obj, $fileName)
|
||||
|
||||
$json = $obj | ConvertTo-Json -Depth 50
|
||||
if((Get-SettingValue "SortJsonProperties") -eq $true)
|
||||
{
|
||||
$json = $obj | ConvertTo-JsonSortedGraph -Depth 50
|
||||
}
|
||||
else
|
||||
{
|
||||
$json = $obj | ConvertTo-Json -Depth 50
|
||||
}
|
||||
|
||||
if($global:Organization.Id)
|
||||
{
|
||||
@@ -4691,6 +4706,144 @@ function Save-GraphObjectToFile
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-SortJsonGraphObject {
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
$InputObject
|
||||
)
|
||||
|
||||
if ($null -eq $InputObject) { return $null }
|
||||
|
||||
if ($InputObject -is [System.Collections.IList]) {
|
||||
$new = @()
|
||||
foreach ($item in $InputObject) {
|
||||
$new += Invoke-SortJsonGraphObject $item
|
||||
}
|
||||
return ,$new
|
||||
}
|
||||
|
||||
if ($InputObject -is [System.Collections.IDictionary] -or
|
||||
$InputObject -is [System.Management.Automation.PSCustomObject]) {
|
||||
|
||||
$props =
|
||||
if ($InputObject -is [System.Collections.IDictionary]) {
|
||||
$InputObject.Keys
|
||||
} else {
|
||||
$InputObject.PSObject.Properties.Name
|
||||
}
|
||||
|
||||
$baseGroups = @{}
|
||||
|
||||
foreach ($p in $props) {
|
||||
if ($p -match '^(.+?)@(.+)$') {
|
||||
$base = $matches[1]
|
||||
if (-not $baseGroups.ContainsKey($base)) {
|
||||
$baseGroups[$base] = @{
|
||||
Base = $null
|
||||
Meta = New-Object System.Collections.ArrayList
|
||||
}
|
||||
}
|
||||
[void]$baseGroups[$base].Meta.Add($p)
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($p in $props) {
|
||||
if ($baseGroups.ContainsKey($p)) {
|
||||
$baseGroups[$p].Base = $p
|
||||
}
|
||||
}
|
||||
|
||||
$atProps = @() # starts with @
|
||||
$hashProps = @() # starts with #
|
||||
$normal = @() # everything else
|
||||
|
||||
foreach ($p in $props) {
|
||||
|
||||
if ($p.StartsWith('@')) {
|
||||
$atProps += $p
|
||||
continue
|
||||
}
|
||||
|
||||
if ($p.StartsWith('#')) {
|
||||
$hashProps += $p
|
||||
continue
|
||||
}
|
||||
|
||||
# If in a baseGroup, skip for now (added later)
|
||||
if ($baseGroups.ContainsKey($p)) {
|
||||
continue
|
||||
}
|
||||
|
||||
$normal += $p
|
||||
}
|
||||
|
||||
$atProps = $atProps | Sort-Object
|
||||
$normal = $normal | Sort-Object
|
||||
$hashProps = $hashProps | Sort-Object
|
||||
|
||||
$orderedNames = @()
|
||||
|
||||
$orderedNames += $atProps
|
||||
|
||||
foreach ($base in ($baseGroups.Keys | Sort-Object)) {
|
||||
|
||||
$meta = $baseGroups[$base].Meta | Sort-Object
|
||||
|
||||
foreach ($m in $meta) {
|
||||
$orderedNames += $m
|
||||
}
|
||||
|
||||
if ($null -ne $InputObject.$base) {
|
||||
$orderedNames += $base
|
||||
}
|
||||
}
|
||||
|
||||
$orderedNames += $normal
|
||||
$orderedNames += $hashProps
|
||||
|
||||
$result = [ordered]@{}
|
||||
foreach ($p in $orderedNames) {
|
||||
$value =
|
||||
if ($InputObject -is [System.Collections.IDictionary]) {
|
||||
$InputObject[$p]
|
||||
} else {
|
||||
$InputObject.$p
|
||||
}
|
||||
|
||||
if($null -ne $value) {
|
||||
$result[$p] = Invoke-SortJsonGraphObject $value
|
||||
}
|
||||
else {
|
||||
$result[$p] = $null
|
||||
}
|
||||
|
||||
if($InputObject.$p -is [Array] -and $result[$p] -isnot [Array]) {
|
||||
if($result[$p] -eq $null) {
|
||||
$result[$p] = @()
|
||||
}
|
||||
else {
|
||||
$result[$p] = @($result[$p])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [pscustomobject]$result
|
||||
}
|
||||
|
||||
return $InputObject
|
||||
}
|
||||
|
||||
function ConvertTo-JsonSortedGraph {
|
||||
param(
|
||||
[Parameter(ValueFromPipeline, Mandatory)]
|
||||
$InputObject,
|
||||
|
||||
[int]$Depth = 50
|
||||
)
|
||||
$sorted = Invoke-SortJsonGraphObject $InputObject
|
||||
return $sorted | ConvertTo-Json -Depth $Depth
|
||||
}
|
||||
|
||||
function Get-GraphObjectFile
|
||||
{
|
||||
param($obj, $objectType, $path)
|
||||
|
||||
Reference in New Issue
Block a user