MDT Scripting: Managing Environment Variables – Part 2

Continuing with the ZTIUtility Environment Class. I again will assume you have read my getting started article here or have basic knowledge of MDT scripting. This class is used for collecting or changing properties gathered by MDT. You can produce scripts and conditions based around these values.

To Read a value and detect information.

Yesterday we used oEnvironment.Item(sName) to update a property value. We can also use the same method to return a value. oEnvironment.Exists(sName) is used to check if a property is not empty. This example will demonstrate both methods. To begin with paste this example code in your MDT Script Template:

If oEnvironment.Exists("_SMSTSORGNAME") then
       wscript.echo "The Property Value = " & oEnvironment.Item("_SMSTSORGNAME")
Else
       wscript.echo "The Property Value is not set!"
End if

If the _SMSTSORGNAME value has not been set in the customsettings.ini then the script will detect that the _SMSTSORGNAME property has no value and display the prompt as below.

Now, modify the code to use the IsVM property as below and run the script again.

If oEnvironment.Exists("IsVM") then
       wscript.echo "The Property Value = " & oEnvironment.Item("IsVM")
Else
       wscript.echo "The Property Value is not set!"
End if

This time it will return a Boolean value (True or False) depending on whether or not you’re running a virtual machine.

The other methods in the ZTIUtility Environment Class are:

oEnvironment.Substitute(sVal)

Given a string, will expand any variables and/or functions within that string.

oEnvironment.ListItem(sName)

Read/Write a variable of type array to a persistent store.

About these ads

About Andrew Barnes

A Scipting and Deployment Specialist.
This entry was posted in MDT 2010, SCCM, Scripting and tagged , , , . Bookmark the permalink.

4 Responses to MDT Scripting: Managing Environment Variables – Part 2

  1. Derek Coleman says:

    how do I use this variable to detect a vm and if is a vm then create a extra disk partition?

    Like this

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s