Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

DO Windows update with(out) MDT

Publié le par damcuvelier

 

deployment with MDT2012 / SCCM2012:
http://scriptimus.wordpress.com/2012/03/22/mdt-2012-automating-updates-in-lite-touch-deployments/

 


deployment with other tools:

add this into regedit:

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate]
"WUServer"="http://<your wsus server>"
"WUStatusServer"=http://<your wsus server>

 

and run this in your deployment sequence:

'========================================================================== ' ' MDT2012 Windows Update Task Sequence ' DATE : 24.01.2013 ' '========================================================================== On error Resume Next Class DummyClass Public Default Function DummyFunction() End Function End Class Dim gethomepath Dim gObjShell, gObjProgressUI, gObjFileSystem, strScriptPath, strCommand, strCurrentUpdate Dim gObjSearchResult, gObjUpdateSearcher, gObjUpdateSession, gObjUpdateCollection, gStrTmpDir Dim gStrWinDir, gStrToolsDir, objDownload, objInstall, gObjDummyDict, varScriptPath, gStrOrgName, gStrTSName Set gObjShell = CreateObject("WScript.Shell") Set gObjFileSystem = CreateObject("Scripting.FileSystemObject") Set gObjUpdateSession = CreateObject("Microsoft.Update.Session") Set gObjUpdateCollection = CreateObject("Microsoft.Update.UpdateColl") Set gObjProgressUI = CreateObject("Microsoft.SMS.TsProgressUI") set env = CreateObject("Microsoft.SMS.TSEnvironment") Set gObjDummyDict = CreateObject("Scripting.Dictionary") Call gObjDummyDict.Add("DummyFunction", New DummyClass) gethomepath = left(WScript.ScriptFullName,len(WScript.ScriptFullName)-len(WScript.ScriptName)-1) gStrOrgName = "<YOUR COMPAGNY>" gStrTSName = "Microsoft Windows Update" gStrWinDir = gObjShell.ExpandEnvironmentStrings("%windir%") gStrTmpDir = gObjShell.ExpandEnvironmentStrings("%temp%") if gObjFileSystem.FileExists("C:\MININT\Tools\X86\TsProgressUI.exe") then gStrToolsDir = "C:\MININT\Tools\X86" elseif gObjFileSystem.FileExists("C:\MININT\Tools\X64\TsProgressUI.exe") then gStrToolsDir = "C:\MININT\Tools\X64" elseif gObjFileSystem.FileExists("C:\MININT\Tools\amd64\TsProgressUI.exe") then gStrToolsDir = "C:\MININT\Tools\amd64" end if Set gObjUpdateDownloader = gObjUpdateSession.CreateUpdateDownloader() fncDebugLog "update.vbs::main", "CreateUpdateDownloader" & vbTab & "Result: " & err.description & "(" & err.number & ")" Set gObjUpdateInstaller = gObjUpdateSession.CreateUpdateInstaller() fncDebugLog "update.vbs::main", "CreateUpdateInstaller" & vbTab & "Result: " & err.description & "(" & err.number & ")" varScriptPath = split(WScript.ScriptFullName, "\") For x = 0 To ubound(varScriptPath) - 1 strScriptPath = strScriptPath & varScriptPath(x) & "\" Next fncDebugLog "update.vbs::main", "strScriptPath :" & strScriptPath & vbTab & "Result: " & err.description & "(" & err.number & ")" strCommand = gStrToolsDir & "\TsProgressUI.exe /Register" gObjShell.Run strCommand,0 ,1 fncDebugLog "update.vbs::main", "Run :" & strCommand & vbTab & "Result: " & err.description & "(" & err.number & ")" '## Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update initialize ...", 1, 4, _ "Configure Windows Update ...", 3, 4) '## Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update initialize ...", 1, 4, _ "Stopping Service ...", 3, 4) strCommand = "net stop wuauserv" gObjShell.Run strCommand,0 ,1 fncDebugLog "update.vbs::main", "Run :" & strCommand & vbTab & "Result: " & err.description & "(" & err.number & ")" '## Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update initialize ...", 1, 4, _ "Starting Service ...", 4, 4) strCommand = "net start wuauserv" gObjShell.Run strCommand,0 ,1 fncDebugLog "update.vbs::main", "Run :" & strCommand & vbTab & "Result: " & err.description & "(" & err.number & ")" '## WScript.Sleep 500 Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update search ...", 2, 4, _ "Checking for Updates ...", 0, 1) '## Set gObjUpdateSearcher = gObjUpdateSession.CreateupdateSearcher() fncDebugLog "update.vbs::main", "CreateupdateSearcher" & vbTab & "Result: " & err.description & "(" & err.number & ")" Set gObjSearchResult = gObjUpdateSearcher.Search("IsInstalled=0 and Type='Software'") fncDebugLog "update.vbs::main", "Search(IsInstalled=0 and Type=Software)" & vbTab & "Result: " & err.description & "(" & err.number & ")" fncDebugLog "update.vbs::main", "UpdateCount :" & gObjSearchResult.Updates.Count & vbTab & "Result: " & err.description & "(" & err.number & ")" Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update search ...", 3, 4, _ "Checking for Updates ...", 1, 1) WScript.Sleep 500 If gObjSearchResult.Updates.Count < 1 Then fncDebugLog "update.vbs::main", "Abort : No Updates Found!" & vbTab & "Result: " & err.description & "(" & err.number & ")" Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update finalize ...", 4, 4, _ "No Updates available !", 1, 1) WScript.Sleep 1000 Set gObjProgressUI = Nothing WScript.Quit Else gObjUpdateDownloader.Updates = gObjSearchResult.Updates gObjUpdateInstaller.Updates = gObjSearchResult.Updates Set objDownload = gObjUpdateDownloader.BeginDownload(gObjDummyDict.Item("DummyFunction"), _ gObjDummyDict.Item("DummyFunction"), _ vbNull) fncDebugLog "update.vbs::main", "BeginDownload" & vbTab & "Result: " & err.description & "(" & err.number & ")" '## Download Updates While Not objDownload.IsCompleted = True If strCurrentUpdate <> gObjUpdateDownloader.Updates.Item(objDownload.GetProgress.CurrentUpdateIndex).Title Then strCurrentUpdate = gObjUpdateDownloader.Updates.Item(objDownload.GetProgress.CurrentUpdateIndex).Title fncDebugLog "update.vbs::main", "Download :" & strCurrentUpdate & vbTab & "Result: " & err.description & "(" & err.number & ")" End If Call gObjProgressUI.ShowActionProgress(gStrOrgName, _ gStrTSName, _ "", _ "Windows Update download (" & (objDownload.GetProgress.CurrentUpdateIndex + 1) & " / " & objDownload.Updates.Count & ")", _ objDownload.GetProgress.CurrentUpdateIndex, _ objDownload.Updates.Count - 1, _ gObjUpdateDownloader.Updates.Item(objDownload.GetProgress.CurrentUpdateIndex).Title, _ objDownload.GetProgress.CurrentUpdatePercentComplete , _ 100) WScript.Sleep 100 Wend Set objDownload = Nothing '## Install Updates Set objInstall = gObjUpdateInstaller.BeginInstall(gObjDummyDict.Item("DummyFunction"), _ gObjDummyDict.Item("DummyFunction"), _ vbNull) fncDebugLog "update.vbs::main", "BeginInstall" & vbTab & "Result: " & err.description & "(" & err.number & ")" While Not objInstall.IsCompleted = True If strCurrentUpdate <> gObjUpdateInstaller.Updates.Item(objInstall.GetProgress.CurrentUpdateIndex).Title Then strCurrentUpdate = gObjUpdateInstaller.Updates.Item(objInstall.GetProgress.CurrentUpdateIndex).Title fncDebugLog "update.vbs::main", "Install :" & strCurrentUpdate & vbTab & "Result: " & err.description & "(" & err.number & ")" End If Call gObjProgressUI.ShowActionProgress(gStrOrgName, _ gStrTSName, _ "", _ "Windows Update install (" & (objInstall.GetProgress.CurrentUpdateIndex + 1) & " / " & objInstall.Updates.Count & ")", _ objInstall.GetProgress.CurrentUpdateIndex, _ objInstall.Updates.Count - 1, _ gObjUpdateInstaller.Updates.Item(objInstall.GetProgress.CurrentUpdateIndex).Title, _ objInstall.GetProgress.CurrentUpdatePercentComplete , _ 100) WScript.Sleep 250 Wend Set objInstall = Nothing if err.number = 0 then env("installwsusupdates") = "OK" else env("installwsusupdates") = err.description & "(" & err.number & ")" end if endlog("windows update sur serveur wsus terminé avec le code erreur de fin:" & vbTab & "Result: " & err.description & "(" & err.number & ")") End If Function fncDebugLog(strFunction, strMessage) Dim objLogFile Set objLogFile = gObjFileSystem.OpenTextFile(gStrTmpDir & "\mdt_wsus_ts.log", 8, 1) objLogFile.WriteLine now() & vbTab & strFunction & vbTab & strMessage objLogFile.Close Set objLogFile = Nothing End Function Function endlog(strMessage) Dim objLog2File Set objLog2File = gObjFileSystem.OpenTextFile(gStrTmpDir & "\mdt_wsus_ts_end.log", 8, 1) objLog2File.WriteLine now() & vbTab & strMessage objLog2File.Close Set objLog2File = Nothing End Function wscript.quit (err.number)

 

do not forget to ignore script error!

 

that’s all folk

Commenter cet article

J
The next white-colored report help you firms by giving assistance with what exactly to search for inside details superior software programs not to mention the best way this amazing software-as-a-service resolution definitely will connect with not to mention meet or exceed its preferences.
Répondre
B
I want to say thank you. Your update for Windows to me very fit. Thank you for your help.
Répondre
S
Je tiens à vous dire merci. Votre mise à jour pour Windows pour moi très en forme. Merci pour votre aide.
Répondre
D
UR Welcome
D
De rien, à venir un script d'automatisation zéro touch des déploiements. Pour faire avec MDT comme si SCCM sans SCCM
C
This article was helpful to me. My updates are installed. However, my Windows Update settings are grayed out and says that they are being managed by policy. How can I change that?
Répondre
D
Hello, this is a vbscript. run this in cscript environment, noy java
Répondre