diff --git a/Core.psm1 b/Core.psm1 index 96cd1c5..64beb69 100644 --- a/Core.psm1 +++ b/Core.psm1 @@ -2757,6 +2757,27 @@ function Format-XML $StringWriter.ToString() } +function Update-XmlFormatting { + [CmdletBinding()] + param( + [Parameter(Mandatory, ValueFromPipeline)] + [string]$Xml + ) + process { + + # 1. Fix empty xml elements → instead of + $Xml = $Xml -replace '<([^\s/>]+)([^>]*)\s/>' , '<$1$2/>' + + # 2. Remove empty lines (lines containing only whitespace or nothing) + $Xml = ($Xml -split "`r?`n") | + Where-Object { $_.Trim().Length -gt 0 } | + ForEach-Object { $_ } | + Out-String + + return $Xml.Trim() + } +} + function Show-LogView { if($script:LogViewObject -and -not $script:LogViewObject.ViewPanel) diff --git a/Extensions/IntuneTools.psm1 b/Extensions/IntuneTools.psm1 index eabaab9..9ab7c78 100644 --- a/Extensions/IntuneTools.psm1 +++ b/Extensions/IntuneTools.psm1 @@ -55,10 +55,25 @@ function Invoke-InitializeModule - + -"@ +"@ + + # Add settings + $global:appSettingSections += (New-Object PSObject -Property @{ + Title = "Intune Tools" + Id = "IntuneTools" + Values = @() + }) + + Add-SettingsObject (New-Object PSObject -Property @{ + Title = "Format OM-URI Settings" + Key = "FormatOMAURI" + Type = "Boolean" + DefaultValue = $false + Description = "Formats the XML for OMA-URI settings e.g. removes unnecessary spaces and empty lines." + }) "IntuneTools" } function Add-EMToolsViewItem @@ -1053,6 +1068,7 @@ function Set-ADMXElementsPanel Write-Log "Unsupported value type for $($elementNode.Id): $($valItem.value.InnerXml)" 2 $value = "" } + $valItems += [PSCustomObject]@{ Name = $displayName Value = $value @@ -1408,18 +1424,23 @@ function Import-ADMXPolicy { if($admxPolicy.SettingStatus -eq 0) { - $policyValue = "" + $policyValue = "" } else { - $policyValue = "" + $policyValue = "" $strValue = $admxPolicy.PolicySettings if($strValue) { - $policyValue += "`n`n$strValue" - } + $policyValue += "`n$strValue" + } + } + + if((Get-SettingValue "FormatOMAURI") -eq $true) + { + $policyValue = Update-XmlFormatting $policyValue } $catPath = Get-ADMXCategoryOMAURIPath $admxPolicy.Definition.parentCategory.ref @@ -1463,12 +1484,18 @@ function Import-ADMXPolicy if($global:chkADMXPolicyIngest.IsChecked) { + $xmlString = Format-XML $script:admxXML + if((Get-SettingValue "FormatOMAURI") -eq $true) + { + $xmlString = Update-XmlFormatting $xmlString + } + $intuneObj.omaSettings += [PSCustomObject]@{ "@odata.type" = "#microsoft.graph.omaSettingString" "displayName" = (?? $global:txtADMXPolicyIngestName.Text ("$($script:currentADMXFile.Name) Ingestion")) "description" = $null "omaUri" = "./Device/Vendor/MSFT/Policy/ConfigOperations/ADMXInstall/$($global:txtADMXPolicyAppName.Text)/Policy/$($global:txtADMXPolicyFileName.Text)" - "value" = (Format-XML $script:admxXML) + "value" = $xmlString } } @@ -1785,7 +1812,7 @@ function Get-ADMXRegIsKeySupported if($blockedSource) { - [System.Windows.MessageBox]::Show("The registry key '$($global:txtADMXRegKey.Text)' is not supported" + [Environment]::NewLine + [Environment]::NewLine + "Blocked by root key: $blockedSource", "Unsupported reg ket", "OK", "Error") + [System.Windows.MessageBox]::Show("The registry key '$($global:txtADMXRegKey.Text)' is not supported" + [Environment]::NewLine + [Environment]::NewLine + "Blocked by root key: $blockedSource", "Unsupported reg key", "OK", "Error") return $false } return $true @@ -1932,6 +1959,11 @@ function Import-ADMXRegProfile $OMAURIString = ($OMAURIString + [Environment]::NewLine + [Environment]::NewLine + ($omaUriItems -join [Environment]::NewLine)) } + if((Get-SettingValue "FormatOMAURI") -eq $true) + { + $OMAURIString = Update-XmlFormatting $OMAURIString + } + $xml.policyDefinitions.SelectSingleNode("policies").AppendChild($newNode) | Out-Null $admxRegSettings += [PSCustomObject]@{ @@ -1944,12 +1976,18 @@ function Import-ADMXRegProfile $xml.policyDefinitions.SelectSingleNode("policies").RemoveChild($xml.policyDefinitions.policies.SelectSingleNode("policy")) | Out-Null + $xmlString = Format-XML $xml + if((Get-SettingValue "FormatOMAURI") -eq $true) + { + $xmlString = Update-XmlFormatting $xmlString + } + $intuneObj.omaSettings += [PSCustomObject]@{ "@odata.type" = "#microsoft.graph.omaSettingString" "displayName" = "Reg ADMX Ingestion" "description" = "This XML is generated by Intune Managemet tool" "omaUri" = "./Device/Vendor/MSFT/Policy/ConfigOperations/ADMXInstall/IntuneManagementReg/$(($script:frmADMXRegProfile.DataContext.PolicyType))/$($rgPolicyFileName)" - "value" = (Format-XML $xml) + "value" = $xmlString } $intuneObj.omaSettings += $admxRegSettings