Writing custom scripts with MDT 2010 November 3, 2009
Posted by tmintner in MDT 2010, VBscript.Tags: custom script, MDT 2010, VBscript
6 comments
Ben Hunter wrote a great blog post a few years ago on how to create a custom VBscript to use with BDD 2007 (http://blogs.technet.com/benhunter/archive/2007/04/15/bdd-2007-ndash-tips-and-tricks-ndash-how-to-write-a-custom-script.aspx). Ben’s script template will still work with MDT 2010 however If you have spent any time looking at the scripts in MDT 2010 you will notice that the format of the built in scripts have changed. So you might be wondering how to create a custom script with MDT 2010. MDT 2010 introduced some script structure changes to better handle error reporting and to make the scripts a bit easier to read and test. The new template is listed below. So how do you use the template? Start by pasting the following code into a script file with a WSF extension (somefile.wsf). After creating the file edit the Class ScriptName with the name of your script. As an example if you named your custom script somescript.wsf then the Class would be Class SomeScript.
Now that you have your script and your class named correctly you can add your code under the Function Main. Once you are finished you just need to save the file and put it into the scripts folder in your deployment share.
So what does the new structure give you beyond what Ben’s post originally pointed out? First it gives you some nice debugging capabilities. Normally you would run your script by calling cscript.exe “%scriptroot%\somescript.wsf” in the task sequence. If you want to use the advanced debugging you can add /debugcapture. Adding the /debugcapture will turn on advanced debugging features by disabling the standard On Error Resume Next in the scripts and capturing any errors in the script that might occur and displaying them to the screen. For example if you forgot to declare a variable the /debugcapture will display the variable that could not be found and the line number that the error occurred on. You can also use your own test hook scripts to unit test the different functions in the script (more on that later). For right now, enjoy the template and we will definitely be posting more custom script samples over the next few months!
<job id=”ZTIConnect”>
<script language=”VBScript” src=”ZTIUtility.vbs”/>
<script language=”VBScript”>
Option Explicit
RunNewInstance
‘//—————————————————————————-
‘// Global Constants
‘//—————————————————————————-
Const ANSWER_TO_LIFE_THE_UNIVERSE_AND_EVERYTHING = 42
‘//—————————————————————————-
‘// Main Class
‘//—————————————————————————-
Class ScriptName
‘//—————————————————————————-
‘// Global constant and variable declarations
‘//—————————————————————————-
Dim iRetVal
‘//—————————————————————————-
‘// Constructor to initialize needed global objects
‘//—————————————————————————-
Private Sub Class_Initialize
End Sub
‘//—————————————————————————-
‘// Main routine
‘//—————————————————————————-
Function Main
‘Insert your code here
End Function
End Class
</script>
</job>
Tim Mintner is a Principal Consultant with Xtreme Consulting Group
Quickly add MSI package to MDT 2010 (New Tool) November 3, 2009
Posted by keithga in MDT 2010, Uncategorized.1 comment so far
New Tool! MDTMSIApp.exe
This tool can quickly import an application defined in a MicroSoft Installer (*.msi) package. This tool will extract out many of the required fields required to import an Applicaiton into MDT 2010 directly from the *.msi meta-data.
One of the most most overlooked features of MDT is the ability to define the “Uninstall registry key name” for each Application Item. When defined, during install time ZTIApplications will skip over the installation of any application by checking the windows registry.
This is a “Best Practice” for applications, as it will save time and errors during installation if a subset of applications were installed previously. The most common scenario is a set of applications that are installed in the base “Common” image before sysprep. Then afterwards, the user is provided a “full” list of applications to install, MDT install will easily skip over any application already installed in the base image.
There is also a command line interface below for scripting.
Fields auto-generated
The following Fields are Auto-Added:
- ShortName – Generated from the name of the *.msi package.
- Folder – Placed in the root of .\Applications by default. Can be changed in the command line.
- Version – From the MSI Package “ProductVersion”.
- UnInstallKey – From MSI Package “ProductCode”.
- Publisher – From MSI Package “Manufacturer”
- Name – From MSI Package “PackageName”
- DisplayName – From MSI Package
“Manufacturer” + “PackageName” + “ProductVersion”
(If the Manufacturer name is duplicated in the PackageName, only one is added). - CommandLine – The following default command line will be used:
‘msiexec.exe /qb- /l*vx %LogPath%\<ShortName>.log REBOOT=ReallySuppress /i <MSIFile>‘
Links
Keith
Keith Garner is a Deployment Specialist with Xtreme Consulting Group