(3/11/2011) Updated a miscount in the code which would not add a single item in a folder.
So I thought I was done with messing around with MDT, packed my stuff, decided to give LiteTouch one last run through. Hm, I feel like installing Adobe Reader, let me just go to the A’s and –GASP! There has been no sorting all this time?! There must be a built in way… Either I suck at finding this option, or it just simply doesn’t exist
There are currently a couple of fixes that I’ve seen by a few helpful fellows.
First there is a helpful powershell script by Michael Niehaus which can be run that sorts everything out, however I really wanted something I could put in, and forget about completely. I believe the script removes, then re-adds, the items. This works because MDT 2010 lists in order of how they were added. I don’t fully understand the script so I can’t say much about specifics, he does list the limitations and warnings at the lower end of the post.
A second useful utility you should definitely check into as well is one created by XTREME Consulting Group, Inc. Not to my tastes however. Do note that it does give more flexibility by letting you order however you’d like. Regardless, I am in search of an even simpler approach. It looks like it works on the same principal as the script above. Again, a great utility and may be better for your tastes so definitely take a look into it.
MDT Code Enhancement
Instead of modifying any data, I decided to tackle this through modifying a single function within MDT’s VBscript code. This would make it much more dynamic: I’d adjust code in one spot that seemed easiest, get it working, and save it. No need to do anything after that, no re-sorting after adding more applications. Fire and forget. The downside is that the sorting code gets run each time on the client, however, its just mild vbscript with moderate degree of looping. Worth the bit of extra second or two of overhead in processing IMO :). Sorting will only take place within the Wizard. While it does not sort the MDT toolbox, I just use column sorting if I’m ever looking for a specific item. The only pain is that you have to click the column when you need sorting; Something I can live with. Below is how you can implement my addition into your code.
- Navigate to your deployment share and open ZTIConfigFile.vbs within the Scripts folder for editing
- Find Private Function BuildHTML_Folder in the code. Directly above it, add the following code. Click HERE for formatted plaintext code.
function GetArrayItemName(oItem) Dim sSortName sSortName = "" If not oItem.SelectSingleNode("./DisplayName") is nothing then sSortName = oItem.SelectSingleNode("./DisplayName").Text End if If sSortName = "" then sSortName = EncodeXML(oUtility.SelectSingleNodeString(oItem,"./Name")) End if GetArrayItemName = sSortName end function Function SortDictionary(objDict) Dim strDict() Dim objKey Dim strKey,strItem Dim X,Y,Z Z = objDict.Count Const dictKey = 1 Const dictItem = 2 'Ensure there is at least two items before continuing If Z > 1 Then 'Create array, each item has the dictionary key and object temporarily ReDim strDict(Z-1,2) X = 0 For Each objKey In objDict.Keys strDict(X,dictKey) = objKey set strDict(X,dictItem) = objDict.Item(objKey) X = X + 1 Next 'X = 0 (outer for) 'Y = X (inner for) 'Z = Count For X = 0 to (Z - 2) For Y = X to (Z - 1) If StrComp(GetArrayItemName(strDict(X,2)), GetArrayItemName(strDict(Y,2)),vbTextCompare) > 0 Then strKey = strDict(X,dictKey) set strItem = strDict(X,dictItem) strDict(X,dictKey) = strDict(Y,dictKey) Set strDict(X,dictItem) = strDict(Y,dictItem) strDict(Y,dictKey) = strKey Set strDict(Y,dictItem) = strItem End If Next Next SortDictionary = strDict Else ReDim strDict(0,2) 'Just fill in single one For Each objKey In objDict.Keys strDict(0,dictKey) = objKey set strDict(0,dictItem) = objDict.Item(objKey) Next SortDictionary = strDict End If End Function
- Find comment ‘ Construct Child Elements and erase the for … next code (3 lines) completely. This code can also can be seen HERE in formatted plain text. The new logic:
Dim dFolder, count dFolder = SortDictionary(FindItemsByFolder(oFolder)) if dFolder(0, 1) <> Empty Then for count = 0 to UBound(dFolder) BuildHTML_Folder = BuildHTML_Folder & BuildHTML_Element ( oFolder, dFolder(count,2) ) next End If
- Save it, you’re set!
Current code is LARGELY untested at this time. Please report any bugs! Folders are not sorted, however if there is demand for this I’m sure I can clear that up as well.