Deployment Wizard Sorting

Deployment Wizard Sorting in action. Note that this works in other parts of deployments as well.

Updates

(3/11/2011) Updated a miscount in the code which would not add a single item in a folder.

Preface

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 :(

Other Utilities

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.

  1. Navigate to your deployment share and open ZTIConfigFile.vbs within the Scripts folder for editing
  2. 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
  3. 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
  4. 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.

Private Function BuildHTML_Folder

Comments 7

  • Hi Mike,

    I implemented the changes that you stated above and although it does sort the Task Sequences list and the Applications list, it appears to break something when I add more applications. I added an application and fully updated the deployment share.I boot froma flash drive and I get to the Task Sequence screen. I choose the task sequence that has the newly added application as a MandatoryApplication, but it is not showing up in the applications list. It is also not set to be hidden. Of course, this isn’t the first thing that I have come across that “should have worked” but didn’t.

    Have you had any one else report this? I unfortunately, am very new to VBScript, so I am not sure where things are pointing. After this round of installs compltes, I will restart the server to see if that has any effect. I did only comment out the previous code, so I can still remove everything that was added and apply the original code. Any help would be greatly appriciated.

  • First off, I recently updated this code a few days ago, if this wasn’t very recent that you added this, be sure to get the latest code above. I had a bug where it would skip over single items in a folder.

    Second off… Just to be sure, double check that you have no architecture requirements in the programs you recently added. Or better yet, just comment out the code in #3 and uncomment the code you removed and let me know if reintroducing the original code brings it back.

    This code is relatively new and I doubt there is a strong use of it out there right now, so I can’t say there is anyone having the same error as you. I’ll recheck the logic this week. Must be a logic error if it is indeed an error, and there is no error message box popping up. If you can figure out what sets off the error I’d love to hear!

  • It appears that changing the code for #3 back to the original worked. It is also still sorting the list, so I am wondering if that even would need changed. I’ll try adding a few more applications and post back what I find.

    Thanks,

    Mike

  • Ok, so apparently I was wrong about the sorting of application after changing the code for #3 back to the original. I was up late last night fixing a script that I wrote and created a new image. I then incorporated it into all the TS that I have and updated the unattend.xml for each TS and did a full update on the Deployment share. THis morning when I boot a system to image it, the TS list and the Applications list are not sorting again, but the application that I added yesterday is still showing up, so that’s a plus. I wish I knew more about VBScript to help out with this problem.

    I’m in no hurry to get this working as I have other applications to add in eventually so if it comes down to implementing it after all applications are imported, then I fine with that. I have my TS set with MandatoryApplications set so picking a TS will automatically check certain applications on the list.

    Thanks,

    Mike

  • Hm, the code re-runs every time though, so it should be adding anything new afterward. I havn’t used MandatoryApplications yet so maybe the problem just lies with that. I’ve been meaning to look into this but I’m already working away at some other script. Check back next week, I’ll recheck everything with additional testing and post up any fixes I can find.

  • Is this code working now? I am after the same functionality…

  • Hi Robert,

    It has always worked for me, I never had time to get back to Mike unfortunately. Why not give it a shot? Just back your files up before the changes. Other people may have had success with this script as well but just never commented afterwards on this blog.

Leave a Reply

Your email address will not be published. Required fields are marked *