In this post I am going to talk about a solution I put together for a customer around OSD and application installation by querying a collection.
Anyone who has used Zero Touch Installation will be familiar with the ability to install applications from SMS packages. In the wizard screen you enter information about each package; the package ID - made up of a site code and a unique number; and the install command line. Then when the task sequence runs ZTIApplications.wsf reads each entry you made and installs the application referenced. This is all well and good but you have to go dig up all the information about a package and enter it into the workbench. If one of the applications changes you need to update the workbench entry again. Plus the person managing BDD may not have enough rights in SMS to to the query.
On the project where I put this solution together the SMS team were responsible for creating application packages and advertising them. The BDD team did not want to have the additional workload of having to manage application updates - which were expected to be frequent. In addition applications would be grouped on core language, business unit or role.
So I wrote a task that would query a named SMS collection, extract a list of adverts, gather the details of each advert - package ID and install command line, sort alphabetically and then pass the list to ZTIApplications.wsf for install.
To be honest this turned out to be surprisingly easy. The hardest bit was working out the permissions required by the script and sorting the list of applications alphabetically.
To make this work you need five things;
- The script to do the query. This can be found on my Live Drive Folder in the zCFG-SMSCollectionQuery.zip file. There is only one script in this file. Extract this to the scriptroot directory.
- You need a BDD environment variable called SMSMgmtPt. This holds the value of the SMS MP you are going to query.
- You need another BDD environment variable, you can call it whatever you want, that holds the name of the collection to query in SMS.
- You need a collection in SMS that has some programs advertised to it. (We used an empty collection but they don't have to be.)
- Your BDD user, the one you use to connect to the BDD shares etc., must have enough rights to query the WMI name space collections and advertisement objects in SMS.
Once you have all these pieces lined up create a task in your Task Sequence that calls the query script and passes the name of the collection to be queried on the command line. For example;
cscript.exe "%SCRIPTROOT%\zCFG-SMSCollectionQuery.wsf /SMSCOL:<variable_name_that_hold_collection_name>
Now run your task sequence. You should see the applications advertised to the collection being installed.
The script can be run multiple times in a task sequence. This allows you to specify different collections each time and build up a list of applications to be installed. Note that you you must run all instances of this task before you run the ZTIApplications task. Also that applications are only sorted for that run of the script. If you run it multiple times it will not sort the whole of the resultant application list.
The script can be downloaded from my Live Drive folder.
So what happens in the script and how does it work?
NOTE: I am a great believer in verbose logging. Pretty much anything the script does gets logged. If it generates an error I try to make sure this is unique for each test within the script - as you will see below. This greatly helps when trouble shooting. If you hit errors go look in the logs and the error code returned should tell you where in the script it failed. For example error 80 means you have not supplied the /SMSCol switch on the command line, an error of 60 means it can not connect to the WMI name space on the management point.
The first thing the script does is checks that it has all the values it needs. The script runs and checks to see is a value for the SMS MP server (SMSMgmtPt) has been specified. If not it returns an error code 90. Then it checks to make sure you have supplied a value on the cmd line for SMSCol. If not it returns an error code of 80.
Then it queries the BDD env var passed to it on the cmd line to see if that holds a value. If it does not it errors with code 70. This is the name of the collection it is going to query.
Now it sees if there are any packages already defined. If there are it works out how many and starts to add packages at the end of the list. This means you can define packages as normal in BDD Workbench – these will be installed before any this script finds. This is also how we are able to run the task multiple times and not overwrite previous entries.
Now it tries to connect to the WMI names space on the server. If it fails to connect you get an error code 65. If successful it gets the site code from WMI. If it can not do this you get an error code of 60.
Now finally it tries to get the collection. If it can not it returns error 50. If it succeeds it gets each advert in the collection, gets the package ID and install cmd line associated with the package and drops these into a collection called coladverts. Once it has the full list it sorts the collection into alphabetical order, using the function QuickSort.
Once they are sorted the script adds each package to the package list then terminates.
The script can run/tested during an LTI test TS. You would only need the OSD functionality if actually installing the packages. See Ben Hunters blog on how to run up quick little test Task Sequences or run scripts on their own.
This post was contributed by Richard Trusson a Senior Consultant with Microsoft Services UK.