Log "ImportCustomDrivers - Start" strComputer = "." strDriverFolder = "ExportedDrivers" intReturnCode = 0 intFinalReturnCode = 0 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set objFSO = CreateObject("Scripting.FileSystemObject") Set oShell = WScript.CreateObject("WScript.Shell") Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk") 'enum each drive letter, and see if strDriverFolder exists in the root. For Each objDisk In colDisks 'Check each drive letter to see if there is a If objFSO.FolderExists(objDisk.DeviceID & "\" & strDriverFolder) Then 'this will only run in a TS environment, so fail if we can't connect to sms.tsenvironment Log vbTab & "Connecting to SMS.TSEnvironment" Set oTSEnv = CreateObject("Microsoft.SMS.TSEnvironment") If err.number <> 0 Then Log vbTAB & "Unable to connect to Microsoft.SMS.TSEnvironment" Log "ImportCustomDrivers - End" WScript.quit(err.number) Else 'prepare the command line, and launch the DISM command Log vbTAB & objDisk.DeviceID & "\" & strDriverFolder & " Exists, Importing drivers.." strCommand = CStr("Dism /image:" & oTSEnv("OSDTARGETSYSTEMDRIVE") & "\ /logpath:%windir%\temp\smstslog\DismCustomImport.log /Add-Driver /driver:" & objDisk.DeviceID & "\" & strDriverFolder & " /recurse") Log vbTAB & "Preparing to run the following command: " & strCommand intReturnCode = oShell.Run(strCommand, 1, True) Log vbTAB & "Return Code = " & intReturnCode Log vbTAB & "Setting TS Variable OSDCustomDriversApplied = True" oTSEnv("OSDCustomDriversApplied") = "True" End If Else 'no custom drivers exist End If 'slightly cheesy - if more than one drive have the special folder, the DISM command will run more than once ' so we're using this to capture if ANY of the exit code are <> 0, so we can capture that if there are any failures ' you'll have to review the %windir%\temp\smstslog\DISMCustomImport.log for details If intReturnCode <> 0 Then intFinalReturnCode = intReturnCode Next Log "Final Return code = " & intFinalReturnCode Log "ImportCustomDrivers - End" WScript.Quit(intFinalReturnCode) 'a simple logging subroutine Sub Log(message) WScript.Echo message Const ForAppending = 8 Set WshShell = CreateObject("WScript.Shell") strSystemRoot = WshShell.ExpandEnvironmentStrings("%SystemRoot%") Set objFSO = CreateObject("Scripting.FileSystemObject") If Not objFSO.FolderExists(strSystemRoot & "\Temp\SMSTSLog\") Then objFSO.CreateFolder(strSystemRoot & "\Temp\SMSTSLog\") End If 'Create Output Log stroutputlog = strSystemRoot & "\temp\SMSTSLog\OSD_CustomDrivers.log" Set objTextFile = objFSO.OpenTextFile(strOutputLog, ForAppending, True) On Error Resume Next txtstatus.value = Trim(Replace((message & " " & Now()), vbTab, "")) On Error Goto 0 message = Now() & " " & message ' ' Log the given message ' objTextFile.writeline(message) objTextFile.Close End Sub