Does anyone know if it possible to instantiate objects remotely using vbs or
powershell? Right now I am trying to use psexec to execute a batch file that
calls a local script on a server to deploy patches using the WSUS client.
The problem is that when I try to use this object Set objDownloader =
objSession.CreateUpdateDownloader() and some of the others I get access
denied. But if remote desktop onto the server it works without any
permission problems. With psexec I have tried the -u parameter so it should
not be using impersonation but the domain admin creds. I have a hole in my
knowledge on using objects like this remotely so any help or experiences
would be helpful. Thanks.
Set fso = CreateObject("Scripting.FileSystemObject")
Set objAutomaticUpdates = CreateObject("Microsoft.Update.AutoUpdate")
Set objComputer = CreateObject("Shell.LocalMachine")
Wscript.Echo "Server name: " & objComputer.MachineName
' Search for updates
objAutomaticUpdates.EnableService
objAutomaticUpdates.DetectNow
Set objSession = CreateObject("Microsoft.Update.Session")
Set objSearcher = objSession.CreateUpdateSearcher()
Set objResults = objSearcher.Search("IsInstalled=0 and Type='Software'")
'Set objResults = objSearcher.Search("Type='Software'")
Set colUpdates = objResults.Updates
' List out updates that were found.
For each objUpdates in colUpdates
Wscript.echo objUpdates
objPatchRecordset.AddNew
objPatchRecordset("Name") = objComputer.MachineName
objPatchRecordset("Patches") = objUpdates
objPatchRecordset.Update
Next
Wscript.Quit
' Download Updates if needed
Set objUpdatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
intUpdateCount = 0
For i = 0 to colUpdates.Count - 1
intUpdateCount = intUpdateCount + 1
Set objUpdate = colUpdates.Item(i)
objUpdatesToDownload.Add(objUpdate)
Next
If intUpdateCount = 0 Then
WScript.Echo "No Patches to Install!"
WScript.Quit
Else
Set objDownloader = objSession.CreateUpdateDownloader()
objDownloader.Updates = objUpdatesToDownload
objDownloader.Download()
' Install updates
Set objInstaller = objSession.CreateUpdateInstaller()
objInstaller.Updates = objUpdatesToDownload
Set installationResult = objInstaller.Install()
' Reboot server if needed
Set objSysInfo = CreateObject("Microsoft.Update.SystemInfo")
If objSysInfo.RebootRequired Then
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonat e,(Shutdown)}!\\localhost\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Reboot()
Next
End If
End If
|