Private/ConvertTo-SortedSidecar.ps1
|
function ConvertTo-SortedSidecar { <# .SYNOPSIS Sorts the directories on a device's sidecar. .DESCRIPTION Sort-BusyLampFields grabs the necessary information of each directory on the device's sidecar given in the DeviceInfo.xml file generated from Get-DeviceInfo.Following, it creates a new XML document (sorted.xml) which sorts the given directories alphabetically. .PARAMETER FileConent The XML content contained in the FileName (DeviceInfo.xml) parameter of Get-DeviceInfo. #> [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [string]$FileName ) BEGIN{} PROCESS { #Create New XML Doc to hold sorted lamp fileds. $SortedFile = "C:\users\$env:USERNAME\Desktop\Sorted.xml" $FileContent = [xml](Get-content $FileName) $DefaultRoutePartition = "Internal_DN-PT" $NewXMLDoc = New-Object System.Xml.XmlDocument [System.XML.XMLElement]$Root = $NewXMLDoc.CreateElement("busyLampFields") [void]$NewXMLDoc.AppendChild($Root) #Sort the nodes currently on the sidecar. $BLFs = $FileContent.SelectNodes("//busyLampFields/busyLampField") $SortedBLFs = $BlFs | Sort-Object -Property label $index = 0 #Take sorted nodes, and add each as an XML element in the new XML Document. foreach($field in $SortedBLFs) { #Create root node of the XML document, 'busyLampField' $NewBLFElement = $NewXMLDoc.CreateElement("busyLampField") [void]$Root.AppendChild($NewBLFElement) #Create blfdirn element, and and directory number. $NewDirn = $NewXMLDoc.CreateElement("blfDirn") $DirnText = $NewXMLDoc.CreateTextNode($field.blfDirn) [void]$NewDirn.AppendChild($DirnText) [void]$NewBLFElement.AppendChild($NewDirn) #Create routePartition element, and add the value. $NewRoutePartition = $NewXMLDoc.CreateElement("routePartition") $NewPartitionText = $NewXMLDoc.CreateTextNode($DefaultRoutePartition) [void]$NewRoutePartition.AppendChild($NewPartitionText) [void]$NewBLFElement.AppendChild($NewRoutePartition) #Create new label element, and add the corresponding text. $NewLabel = $NewXMLDoc.CreateElement("label") $NewLabelText = $NewXMLDoc.CreateTextNode($field.label) [void]$NewLabel.AppendChild($NewLabelText) [void]$NewBLFElement.AppendChild($NewLabel) ##ADDED TO JAYSON'S SECOND USE. NEW FEATURE. ## if($FileContent.SelectNodes("//associatedBlfsdFeatures")){ $Feature = "Pickup" #Create new associatedblfsdFeaturesElement, add to the busyLampField Elemnt $NewBLFAssociatedFeature = $NewXMLDoc.CreateElement("associatedBlfSdFeatures") [void]$NewBLFElement.AppendChild($NewBLFAssociatedFeature) #Create the feature element, add corresponding text, and append to the associatedfeature element. $NewBLFFeature = $NewXMLDoc.CreateElement("feature") $NewFeatureText =$NewXMLDoc.CreateTextNode($Feature) [void]$NewBLFFeature.AppendChild($NewFeatureText) [void]$NewBLFAssociatedFeature.AppendChild($NewBLFFeature) ##END NEW ADDITION } #Create new index element, and increment by 1 for each busy lamp field. $index = $index + 1 $IndexNode = $NewXMLDoc.CreateElement("index") $IndexText = $NewXMLDoc.CreateTextNode($index) [void]$IndexNode.AppendChild($IndexText) [void]$NewBLFElement.AppendChild($IndexNode) } [void]$NewXMLDoc.save($SortedFile) } #PROCESS END{} } |