Using ConvertBooleanToString with ZTIGather.wsf in MDT 2010
Update 2010-07-08: This issue has now been fixed in MDT 2010 Update 1. You can now use ConvertBooleanToString directly without these workarounds in MDT 2010 Update 1. |
In a few of my previous posts I used the ConvertBooleanToString function found in ZTIGather.wsf to correctly set values of “True” or “False” for custom MDT properties. Examples can be found here for use in a User Exit script and here for use in a #VBScript evaluate block# line in CustomSettings.ini . However, I had never tested this usage with the MDT 2010 version of ZTIGather.wsf. Well, thanks to a comment posted by a reader named Mike found here I went ahead and tested these scenarios. Lo and behold they no longer work, as Mike has said.
After some investigating and an email exchange with the MDT Team, I have found out why it no longer works and have found a few workarounds. This change is a result of the fact that the MDT 2010 .wsf scripts have been re-architected with all the functions being embedded in a VBScript Class. This makes it easier for the MDT Team to do unit testing of functions during development. However, this change means that the functions are no longer available in the global script scope, which is how User Exit scripts and #VBScript evaluate block# lines are executed.
There are several ways to work around this problem. This first is the one Mike found for User Exit scripts, which is to simply place a copy ConvertBooleanToString into your User Exit scripts. This works but means having to keep a copy in every User Exit script where it is needed.
The second is similar to the first but only requires one copy of the function. Place a copy ConvertBooleanToString into its own User Exit script and then call this from a CustomSettings.ini section earlier in the Priority line than the sections where the functions are used. I’ve attached a copy of such a script (MDTExitConvertBooleanToString.vbs) below. This allows you to continue to use ConvertBooleanToString directly in both User Exit scripts or #VBScript evaluate block# lines as before. For example, here is the CustomSettings.ini sample from this post updated with this script (additions shown in green):
[Settings]
Priority=CvtBoolToStrExit, TimeZone, TestLegacyOS
Properties=TimeZoneStandardName, TimeZoneCaption, IsLegacyOS[CvtBoolToStrExit]
UserExit=MDTExitConvertBooleanToString.vbs[TimeZone]
UserExit=GetCurrentTimeZoneExit.vbs
TimeZoneStandardName=#GetCurrentTimeZoneWmiProperty("StandardName")#
TimeZoneCaption=#GetCurrentTimeZoneWmiProperty("Caption")#
TimeZoneName=#GetCurrentTimeZoneRegistryKeyName#
IsLegacyOS=#ConvertBooleanToString(%OSCurrentBuild% < 5200)#[TestLegacyOS]
SubSection=IsLegacyOS-%IsLegacyOS%[IsLegacyOS-True]
TimeZone=#GetCurrentTimeZoneLegacyIndex#
The final way was provided by the MDT Team (thanks Keith!). This requires actually creating an instance of the ZTIGather class found in the MDT 2010 version of ZTIGather.wsf so that the function can be used. Here is the same sample updated with this technique (additions shown in green):
[Settings]
Priority=TimeZone, TestLegacyOS
Properties=TimeZoneStandardName, TimeZoneCaption, IsLegacyOS[TimeZone]
UserExit=GetCurrentTimeZoneExit.vbs
TimeZoneStandardName=#GetCurrentTimeZoneWmiProperty("StandardName")#
TimeZoneCaption=#GetCurrentTimeZoneWmiProperty("Caption")#
TimeZoneName=#GetCurrentTimeZoneRegistryKeyName#
IsLegacyOS=#(New ZTIGather).ConvertBooleanToString(%OSCurrentBuild% < 5200)#[TestLegacyOS]
SubSection=IsLegacyOS-%IsLegacyOS%[IsLegacyOS-True]
TimeZone=#GetCurrentTimeZoneLegacyIndex#
Here is a sample of this method used inside a User Exit script. (This is a trivial sample where I’ve rewritten the IsLegacyOS #VBScript evaluate block# shown above as a User Exit script to illustrate the point. Usage shown in green.)
Function UserExit(sType, sWhen, sDetail, bSkip)
oLogging.CreateEntry "USEREXIT:IsLegacyOS.vbs started: " & sType & " " & sWhen & " " & sDetail, LogTypeInfo
UserExit = Success
End FunctionFunction IsLegacyOS()
Dim oGather
Set oGather = New ZTIGather
IsLegacyOS = oGather.ConvertBooleanToString(oEnvironment.Item("OSCurrentBuild") < 5200)
End Function
The disadvantage of this method is that it is not backward compatible with MDT 2008. For now, I’m going to stick with the second method of using MDTExitConvertBooleanToString.vbs. It only requires a small change to CustomSettings.ini and no changes to existing User Exit scripts or #VBScript evaluate block# lines. Also, there may be changes in the next update to MDT to make this function more accessible. So I would not want to make additional code changes until that happens.
Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use .
This post was contributed by Michael Murgolo, a Senior Consultant with Microsoft Services - U.S. East Region.
MDTExitConvertBooleanToString.zip
Comments
Anonymous
January 01, 2003
In MDT 2008, we had various functions in the ZTIUtility.vbs script that could be used in CustomSettingsAnonymous
January 01, 2003
In MDT 2008, we had various functions in the ZTIUtility.vbs script that could be used in CustomSettings