Home
%3CLINGO-SUB%20id%3D%22lingo-sub-706909%22%20slang%3D%22en-US%22%3ESorting%20MDT's%20lists%20of%20applications%2C%20task%20sequences%2C%20patches%2C%20etc.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-706909%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20TechNet%20on%20Jun%2020%2C%202008%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EIt%20seems%20to%20be%20a%20common%20request%3A%26nbsp%3B%20You%20want%20the%20MDT%20Deployment%20Wizard%20to%20show%20items%20sorted%20alphabetically.%26nbsp%3B%20So%20here's%20a%20simple%20script%20to%20do%20that%3A%3C%2FP%3E%0A%20%20%3CBLOCKQUOTE%3E%0A%20%20%20%3CP%3E'%20First%20parameter%3A%26nbsp%3B%20XML%20file%20name%20%3CBR%20%2F%3E%20'%20Second%20parameter%3A%20name%20of%20the%20element%20to%20sort%20on%2C%20e.g.%20Name%20(case-sensitive)%3C%2FP%3E%0A%20%20%20%3CP%3EIf%20WScript.Arguments.Count%20%26lt%3B%26gt%3B%202%20then%20%3CBR%20%2F%3E%20WScript.Echo%20%22Usage%3A%20cscript.exe%20SortXML.vbs%20%3CFILENAME%3E%20%3CNODE%20to%3D%22%22%20sort%3D%22%22%20on%3D%22%22%3E%22%20%3CBR%20%2F%3E%20WScript.Echo%20%22Sample%3A%20cscript.exe%20SortXML.vbs%20C%3A%5CDistribution%5CControl%5CApplications.xml%20Name%22%20%3CBR%20%2F%3E%20WScript.Quit%20%3CBR%20%2F%3E%20End%20if%3C%2FNODE%3E%3C%2FFILENAME%3E%3C%2FP%3E%0A%20%20%20%3CP%3E'%20First%20load%20the%20specified%20XML%20file%20%3CBR%20%2F%3E%20Set%20oXML%20%3D%20CreateObject(%22MSXML2.DOMDocument%22)%20%3CBR%20%2F%3E%20oXML.PreserveWhiteSpace%20%3D%20true%20%3CBR%20%2F%3E%20oXML.Async%20%3D%20false%20%3CBR%20%2F%3E%20If%20not%20oXML.Load(WScript.Arguments(0))%20then%20%3CBR%20%2F%3E%20WScript.Echo%20%22Unable%20to%20load%20XML%20file%20%22%20%26amp%3B%20WScript.Arguments(0)%20%26amp%3B%20%22%2C%20aborting%22%20%3CBR%20%2F%3E%20WScript.Quit%20%3CBR%20%2F%3E%20End%20if%3C%2FP%3E%0A%20%20%20%3CP%3E'%20Populate%20the%20XSL%20transform%3C%2FP%3E%0A%20%20%20%3CP%3ESet%20oXSL%20%3D%20CreateObject(%22MSXML2.DOMDocument%22)%3C%2FP%3E%0A%20%20%20%3CP%3EoXSL.loadXML%20%22%3CSTYLESHEET%20version%3D%22%26quot%3B%26quot%3B1.0%26quot%3B%26quot%3B%22%20xsl%3D%22%26quot%3B%26quot%3B%22%3E%3CA%20href%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2FXSL%2FTransform%26quot%3B%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fwww.w3.org%2F1999%2FXSL%2FTransform%22%22%20%3C%2FA%3E%20%26gt%3B%22%20%26amp%3B%20_%20%3CBR%20%2F%3E%20%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CTEMPLATE%20match%3D%22%26quot%3B%26quot%3B%40*%7Cnode()%26quot%3B%26quot%3B%22%3E%3CCOPY%3E%3CAPPLY-TEMPLATES%20select%3D%22%26quot%3B%26quot%3B%40*%7Cnode()%26quot%3B%26quot%3B%22%3E%3CSORT%20select%3D%22%26quot%3B%26quot%3B%26quot%3B%22%3E%3C%2FSORT%3E%3C%2FAPPLY-TEMPLATES%3E%3C%2FCOPY%3E%3C%2FTEMPLATE%3E%22%20%26amp%3B%20_%20%3CBR%20%2F%3E%20%22%3C%2FSTYLESHEET%3E%22%3C%2FP%3E%0A%20%20%20%3CP%3E'%20Transform%20the%20XML%20and%20save%20it%20back%3C%2FP%3E%0A%20%20%20%3CP%3EoXML.transformNodeToObject%20oXSL%2C%20oXML%20%3CBR%20%2F%3E%20oXML.Save%20WScript.Arguments(0)%3C%2FP%3E%0A%20%20%3C%2FBLOCKQUOTE%3E%0A%20%20%3CP%3ESave%20this%20as%20%22SortXML.vbs%22%20and%20then%20you%20can%20do%20things%20like%20this%20(substituting%20appropriate%20paths%20for%20your%20environment)%3A%3C%2FP%3E%0A%20%20%3CBLOCKQUOTE%3E%0A%20%20%20%3CP%3Ecscript.exe%20SortXML.vbs%20C%3A%5CDistribution%5CControl%5CApplications.xml%20FullName%3C%2FP%3E%0A%20%20%20%3CP%3Ecscript.exe%20SortXML.vbs%20C%3A%5CDistribution%5CControl%5CTaskSequences.xml%20Name%3C%2FP%3E%0A%20%20%20%3CP%3Ecscript.exe%20SortXML.vbs%20C%3A%5CDistribution%5CControl%5CDrivers.xml%20Name%3C%2FP%3E%0A%20%20%3C%2FBLOCKQUOTE%3E%0A%20%20%3CP%3EFor%20safety%2C%20make%20sure%20you%20have%20a%20backup%20copy%20of%20the%20file%20before%20you%20do%20this.%26nbsp%3B%20And%20don't%20do%20this%20while%20the%20Deployment%20Workbench%20is%20running%2C%20as%20it%20could%20overwrite%20your%20sorted%20file.%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-706909%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20TechNet%20on%20Jun%2020%2C%202008%20It%20seems%20to%20be%20a%20common%20request%3A%26nbsp%3B%20You%20want%20the%20MDT%20Deployment%20Wizard%20to%20show%20items%20sorted%20alphabetically.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-706909%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Emichael%20niehaus%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft
First published on TechNet on Jun 20, 2008

It seems to be a common request:  You want the MDT Deployment Wizard to show items sorted alphabetically.  So here's a simple script to do that:

' First parameter:  XML file name
' Second parameter: name of the element to sort on, e.g. Name (case-sensitive)

If WScript.Arguments.Count <> 2 then
WScript.Echo "Usage: cscript.exe SortXML.vbs <filename> <node to sort on>"
WScript.Echo "Sample: cscript.exe SortXML.vbs C:\Distribution\Control\Applications.xml Name"
WScript.Quit
End if

' First load the specified XML file
Set oXML = CreateObject("MSXML2.DOMDocument")
oXML.PreserveWhiteSpace = true
oXML.Async = false
If not oXML.Load(WScript.Arguments(0)) then
WScript.Echo "Unable to load XML file " & WScript.Arguments(0) & ", aborting"
WScript.Quit
End if

' Populate the XSL transform

Set oXSL = CreateObject("MSXML2.DOMDocument")

oXSL.loadXML "<xsl:stylesheet version=""1.0"" xmlns:xsl="" http://www.w3.org/1999/XSL/Transform"" >" & _
"    <xsl:template match=""@*|node()""><xsl:copy><xsl:apply-templates select=""@*|node()""><xsl:sort select=""" & WScript.Arguments(1) & """ /></xsl:apply-templates></xsl:copy></xsl:template>" & _
"</xsl:stylesheet>"

' Transform the XML and save it back

oXML.transformNodeToObject oXSL, oXML
oXML.Save WScript.Arguments(0)

Save this as "SortXML.vbs" and then you can do things like this (substituting appropriate paths for your environment):

cscript.exe SortXML.vbs C:\Distribution\Control\Applications.xml FullName

cscript.exe SortXML.vbs C:\Distribution\Control\TaskSequences.xml Name

cscript.exe SortXML.vbs C:\Distribution\Control\Drivers.xml Name

For safety, make sure you have a backup copy of the file before you do this.  And don't do this while the Deployment Workbench is running, as it could overwrite your sorted file.