private/Format-AppVentiXPublishingTasksXml.ps1

<#
    .SYNOPSIS
        Formats the AppVentiX publishing tasks XML document.
 
    .DESCRIPTION
        This function formats the AppVentiX publishing tasks XML document by adding missing fields and elements.
 
    .PARAMETER XmlDocument
        The XML document to be formatted.
 
    .NOTES
        Function : Format-AppVentiXPublishingTasksXml
        Author : John Billekens
        Copyright: Copyright (c) AppVentiX
        Version : 1.0
#>

function Format-AppVentiXPublishingTasksXml {
    [CmdletBinding()]
    Param(
        [System.Xml.XmlDocument]$XmlDocument
    )
    if ([String]::IsNullOrEmpty($XmlDocument) -or ($XmlDocument.HasChildNodes -eq $false)) {
        $XmlDocument = New-Object -TypeName System.Xml.XmlDocument
        Write-Verbose "No current settings found, creating new layout..."
    }
    if (-Not ($ptRootElement = $XmlDocument.SelectSingleNode("Root"))) {
        $ptRootElement = $XmlDocument.AppendChild($XmlDocument.CreateElement("Root"))
        Write-Verbose "Root element created"
    }
    if (-Not ($ptGlobalPublishingTasksElement = $ptRootElement.SelectSingleNode('GlobalPublishingTasks'))) {
        $ptGlobalPublishingTasksElement = $ptRootElement.AppendChild($XmlDocument.CreateElement("GlobalPublishingTasks"))
        Write-Verbose "GlobalPublishingTasks element created"
    }
    if (-Not ($ptGlobalPublishingTasksElement.SelectSingleNode('Connectiongroups'))) {
        $null = $ptGlobalPublishingTasksElement.AppendChild($XmlDocument.CreateElement("Connectiongroups"))
        Write-Verbose "Connectiongroups element created"
    }
    if (-Not ($ptGlobalPublishingTasksElement.SelectSingleNode('Packages'))) {
        $null = $ptGlobalPublishingTasksElement.AppendChild($XmlDocument.CreateElement("Packages"))
        Write-Verbose "Packages element created"
    }
    if (-Not ($ptUserPublishingTasksElement = $ptRootElement.SelectSingleNode('UserPublishingTasks'))) {
        $ptUserPublishingTasksElement = $ptRootElement.AppendChild($XmlDocument.CreateElement("UserPublishingTasks"))
        Write-Verbose "UserPublishingTasks element created"
    }
    if (-Not ($ptUserPublishingTasksElement.SelectSingleNode('Connectiongroups'))) {
        $null = $ptUserPublishingTasksElement.AppendChild($XmlDocument.CreateElement("Connectiongroups"))
        Write-Verbose "Connectiongroups element created"
    }
    if (-Not ($ptUserPublishingTasksElement.SelectSingleNode('Sharedcontainers'))) {
        $null = $ptUserPublishingTasksElement.AppendChild($XmlDocument.CreateElement("Sharedcontainers"))
        Write-Verbose "Sharedcontainers element created"
    }
    if (-Not ($ptUserPublishingTasksElement.SelectSingleNode('Packages'))) {
        $null = $ptUserPublishingTasksElement.AppendChild($XmlDocument.CreateElement("Packages"))
        Write-Verbose "Packages element created"
    }
    return $XmlDocument
}