以下示例主要是用来判断内存大小、C盘空间大小及系统盘符,然后自动选择执行不同的任务序列,具体想依据什么来判断,可参考ZTIGahter.log中的变量
一、依据内存大小,选择执行不同的TS
法一:
Userexit=MyCustomFunctions.vbs
TaskSequenceID=#GetTSID()#
然后将MyCustomFunctions.vbs脚本添加到\\MDT2012\DeploymentShare$\scripts文件夹下即可。
Function UserExit(sType, sWhen, sDetail, bSkip) UserExit = Success End Function Function GetTSID() If oEnvironment.Item("Memory") < 1024 Then GetTSID = "WIN7_TS1" Else GetTSID = "WIN7_TS2" End if End Function
法二:(未借助MDT原有变量Memory,自定义的变量)
Userexit=1.vbs
TaskSequenceID=#GetTSID()#
Function UserExit(sType, sWhen, sDetail, bSkip) UserExit = Success End Function Function GetTSID() strComputer = "." Set objWMI = GetObject("winmgmts:\\" & strComputer) Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem") For Each objItem in colItems If objItem.TotalVisibleMemorySize / 1024 > 1024 Then GetTSID = "WIN7_TS1" Else GetTSID = "WIN7_TS2" End if Next End Function
法三:
Userexit=2.vbs
TaskSequenceID=#SetTaskSequence(%Memory%)#
Function UserExit(sType, sWhen, sDetail, bSkip) UserExit = Success End Function Function SetTaskSequence(Memory) oLogging.CreateEntry "UserExit - Determining Task " & _ "Sequence to run based on available RAM", LogTypeInfo If Memory <= 2048 Then SetTaskSequence = "Win7_TS2" oLogging.CreateEntry "UserExit - Available RAM: " & _ Memory & ". Selecting Win7_Ts2 TS.", LogTypeInfo Else SetTaskSequence = "Win7_TS1" oLogging.CreateEntry "UserExit - Available RAM: " & _ Memory & ". Selecting Win7_TS1 TS.", LogTypeInfo End If End Function
二、依据内存、磁盘空间大小并判断是否为系统盘符决定是否进行Refresh升级
' // *************************************************************************** ' // ' // Copyright (c) Microsoft Corporation. All rights reserved. ' // ' // Microsoft Deployment Toolkit Solution Accelerator ' // ' // File: UserExit.vbs ' // ' // Version: 1.0 ' // ' // Purpose: 内存大小和系统盘符判断 ' // ' // Userexit=UserExit.vbs ' // TaskSequenceID=#GetTSID()# ' // ' // *************************************************************************** '******** BEGIN UserExit.vbs ********* Function UserExit(sType, sWhen, sDetail, bSkip) UserExit = Success End Function Function GetTSID() Set objWMIService = GetObject("winmgmts:\\.") set objFSO = CreateObject("Scripting.FileSystemObject") Set objDiskId = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk") For Each objDisk in objDiskId ' //如果磁盘空间不为空(避免光驱提示插入磁盘错误)且大于1G,然后执行以下动作 If Not isNull(objDisk.Size) And objDisk.Size/1024/1024/1024 > 1 Then ' //如果目标盘符有“Windows”文件夹则继续以下动作 If objFSO.FolderExists(objDisk.DeviceId & "\windows") Then ' //如果是If objFSO.FolderExists(objDisk.DeviceId & "\windows\System32") Then,则是查看目标盘符中是否有System32文件夹,当然,Windows文件也必须存在,因为是从Windows文件夹下查看。 ' //如果是If objFSO.FolderExists(objDisk.DeviceId & "\windows") And objFSO.FolderExists(objDisk.DeviceId & "\Program Files") Then,则是查看目标盘符下是否同时存在Windows文件夹和Program Files文件夹。 ' //如果目标盘符小于9G则执行Win7_TS3任务序列(Pause),大于9G则继续以下动作 If objDisk.Size/1024/1024/1024 < 9 Then GetTSID = "WIN7_TS3" ' //如果目标机器满足以上要求且内存大于1000M则执行Win7_TS7,小于则执行Win7_TS5. Elseif oEnvironment.Item("Memory") >1000 Then GetTSID = "WIN7_TS7" Else GetTSID = "WIN7_TS5" End If End If End If ' //跳出IF语句,执行下一步 Next End Function
当然,也可参照:
http://myitforum.com/cs2/blogs/cnackers/archive/2010/11/02/microsoft-deployment-toolkit-mdt-user-exit-scripts.aspx