mirror of
https://github.com/Micke-K/IntuneManagement.git
synced 2026-09-28 10:55:38 +02:00
3.10.1.10
Issue 380 - ADMX Import / Reg Values fails because of XML format.
This commit is contained in:
@@ -2757,6 +2757,27 @@ function Format-XML
|
|||||||
$StringWriter.ToString()
|
$StringWriter.ToString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Update-XmlFormatting {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory, ValueFromPipeline)]
|
||||||
|
[string]$Xml
|
||||||
|
)
|
||||||
|
process {
|
||||||
|
|
||||||
|
# 1. Fix empty xml elements → <tag/> instead of <tag />
|
||||||
|
$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
|
function Show-LogView
|
||||||
{
|
{
|
||||||
if($script:LogViewObject -and -not $script:LogViewObject.ViewPanel)
|
if($script:LogViewObject -and -not $script:LogViewObject.ViewPanel)
|
||||||
|
|||||||
@@ -55,10 +55,25 @@ function Invoke-InitializeModule
|
|||||||
|
|
||||||
<elements>
|
<elements>
|
||||||
</elements>
|
</elements>
|
||||||
</policy>
|
</policy>
|
||||||
</policies>
|
</policies>
|
||||||
</policyDefinitions>
|
</policyDefinitions>
|
||||||
"@
|
"@
|
||||||
|
|
||||||
|
# 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
|
function Add-EMToolsViewItem
|
||||||
@@ -1053,6 +1068,7 @@ function Set-ADMXElementsPanel
|
|||||||
Write-Log "Unsupported value type for $($elementNode.Id): $($valItem.value.InnerXml)" 2
|
Write-Log "Unsupported value type for $($elementNode.Id): $($valItem.value.InnerXml)" 2
|
||||||
$value = "<SET MANUALLY!!!>"
|
$value = "<SET MANUALLY!!!>"
|
||||||
}
|
}
|
||||||
|
|
||||||
$valItems += [PSCustomObject]@{
|
$valItems += [PSCustomObject]@{
|
||||||
Name = $displayName
|
Name = $displayName
|
||||||
Value = $value
|
Value = $value
|
||||||
@@ -1408,18 +1424,23 @@ function Import-ADMXPolicy
|
|||||||
{
|
{
|
||||||
if($admxPolicy.SettingStatus -eq 0)
|
if($admxPolicy.SettingStatus -eq 0)
|
||||||
{
|
{
|
||||||
$policyValue = "<disabled />"
|
$policyValue = "<disabled/>"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$policyValue = "<enabled />"
|
$policyValue = "<enabled/>"
|
||||||
|
|
||||||
$strValue = $admxPolicy.PolicySettings
|
$strValue = $admxPolicy.PolicySettings
|
||||||
|
|
||||||
if($strValue)
|
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
|
$catPath = Get-ADMXCategoryOMAURIPath $admxPolicy.Definition.parentCategory.ref
|
||||||
@@ -1463,12 +1484,18 @@ function Import-ADMXPolicy
|
|||||||
|
|
||||||
if($global:chkADMXPolicyIngest.IsChecked)
|
if($global:chkADMXPolicyIngest.IsChecked)
|
||||||
{
|
{
|
||||||
|
$xmlString = Format-XML $script:admxXML
|
||||||
|
if((Get-SettingValue "FormatOMAURI") -eq $true)
|
||||||
|
{
|
||||||
|
$xmlString = Update-XmlFormatting $xmlString
|
||||||
|
}
|
||||||
|
|
||||||
$intuneObj.omaSettings += [PSCustomObject]@{
|
$intuneObj.omaSettings += [PSCustomObject]@{
|
||||||
"@odata.type" = "#microsoft.graph.omaSettingString"
|
"@odata.type" = "#microsoft.graph.omaSettingString"
|
||||||
"displayName" = (?? $global:txtADMXPolicyIngestName.Text ("$($script:currentADMXFile.Name) Ingestion"))
|
"displayName" = (?? $global:txtADMXPolicyIngestName.Text ("$($script:currentADMXFile.Name) Ingestion"))
|
||||||
"description" = $null
|
"description" = $null
|
||||||
"omaUri" = "./Device/Vendor/MSFT/Policy/ConfigOperations/ADMXInstall/$($global:txtADMXPolicyAppName.Text)/Policy/$($global:txtADMXPolicyFileName.Text)"
|
"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)
|
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 $false
|
||||||
}
|
}
|
||||||
return $true
|
return $true
|
||||||
@@ -1932,6 +1959,11 @@ function Import-ADMXRegProfile
|
|||||||
$OMAURIString = ($OMAURIString + [Environment]::NewLine + [Environment]::NewLine + ($omaUriItems -join [Environment]::NewLine))
|
$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
|
$xml.policyDefinitions.SelectSingleNode("policies").AppendChild($newNode) | Out-Null
|
||||||
|
|
||||||
$admxRegSettings += [PSCustomObject]@{
|
$admxRegSettings += [PSCustomObject]@{
|
||||||
@@ -1944,12 +1976,18 @@ function Import-ADMXRegProfile
|
|||||||
|
|
||||||
$xml.policyDefinitions.SelectSingleNode("policies").RemoveChild($xml.policyDefinitions.policies.SelectSingleNode("policy")) | Out-Null
|
$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]@{
|
$intuneObj.omaSettings += [PSCustomObject]@{
|
||||||
"@odata.type" = "#microsoft.graph.omaSettingString"
|
"@odata.type" = "#microsoft.graph.omaSettingString"
|
||||||
"displayName" = "Reg ADMX Ingestion"
|
"displayName" = "Reg ADMX Ingestion"
|
||||||
"description" = "This XML is generated by Intune Managemet tool"
|
"description" = "This XML is generated by Intune Managemet tool"
|
||||||
"omaUri" = "./Device/Vendor/MSFT/Policy/ConfigOperations/ADMXInstall/IntuneManagementReg/$(($script:frmADMXRegProfile.DataContext.PolicyType))/$($rgPolicyFileName)"
|
"omaUri" = "./Device/Vendor/MSFT/Policy/ConfigOperations/ADMXInstall/IntuneManagementReg/$(($script:frmADMXRegProfile.DataContext.PolicyType))/$($rgPolicyFileName)"
|
||||||
"value" = (Format-XML $xml)
|
"value" = $xmlString
|
||||||
}
|
}
|
||||||
|
|
||||||
$intuneObj.omaSettings += $admxRegSettings
|
$intuneObj.omaSettings += $admxRegSettings
|
||||||
|
|||||||
Reference in New Issue
Block a user