VBSCRIPT call WMI Method on array

We still have some windows server 2003 servers without powershell. We have a need to install SCCM updates with vbscript. I can instantiate the updates, but I am not able to call the installupdates WMI method for CCM_SoftwareUpdatesManager

Here is what I have

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\ccm\ClientSDK")
Set objInstall = GetObject("winmgmts:\\" & strComputer & "\root\ccm\ClientSDK:CCM_SoftwareUpdatesManager")
Set colItems = objWMIService.ExecQuery("SELECT * FROM CCM_SoftwareUpdate WHERE ComplianceState=0", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
'----Get the Patch ID
WScript.Echo "BulletinID: " & objItem.BulletinID
WScript.Echo
' ---- Install the patch
Set UID = objInstall.Methods_("InstallUpdates")
UID = objInstall.InstallUpdates(objItem.BulletinID)
Next

This is the error I am receiving:

 SWbemObjectEx: Type mismatch

Thanks in advance for the help. I have not done any work in vbscript for a while...

December 11th, 2014 9:23pm

That is not the whole error message.

Post in SCCM forum and ask specifically how to use SCCM to install uopdates on WS2003 server.  I think you will find it easier.

Free Windows Admin Tool Kit Click here and download it now
December 11th, 2014 10:28pm

Here is a closer version of a correct script.

REmemebr this has to execute on teh remote system.  It cannot run locally

Set objWMIService = GetObject("winmgmts:\\.\root\ccm\ClientSDK")
Set objInstall = GetObject("winmgmts:\\" & strComputer & "\root\ccm\ClientSDK:CCM_SoftwareUpdatesManager")
Set colItems = objWMIService.ExecQuery("SELECT * FROM CCM_SoftwareUpdate WHERE ComplianceState=0")
For Each objItem In colItems
   objInstall.InstallUpdates objItem.BulletinID
Next

December 11th, 2014 10:32pm

Thanks for the help!! I really appreciate it

I am closer, but I cannot find what the parameter is to pass. I am receiving a type mismatch error. I tried calling objInstall.InstallUpdates with objItem.ArticleID  objItem.UpdateID and objItem.BulletinID

There is the code:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\ccm\ClientSDK")
Set objInstall = GetObject("winmgmts:\\" & strComputer & "\root\ccm\ClientSDK:CCM_SoftwareUpdatesManager")
Set colItems = objWMIService.ExecQuery("SELECT * FROM CCM_SoftwareUpdate WHERE ComplianceState=0", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
'----Get the Patch ID
WScript.Echo "BulletinID: " & objItem.BulletinID
WScript.Echo "UpdateID: " & objItem.UpdateID
WScript.Echo "ArticleID: " & objItem.ArticleID
objInstall.InstallUpdates objItem.ArticleID
Next

I found this link to a powershell script that has a comment stating you need to format the missing updates. It looks like you need to select the path?

https://gallery.technet.microsoft.com/scriptcenter/Install-All-Missing-8ffbd525#content

Free Windows Admin Tool Kit Click here and download it now
December 12th, 2014 3:40pm

Hi,

Why are you trying to script this? If you have ConfigMgr in place you shouldn't need a script to install any updates.

December 12th, 2014 3:58pm

We need to script this because we have some distributed applications that need to be brought down and back up in order. The have database and application dependencies. We currently script it through WSUS, but we want to migrate to SCCM for all updates. These are older servers and we cannot leverage powershell.
Free Windows Admin Tool Kit Click here and download it now
December 12th, 2014 4:46pm

Mike, 

Did you ever figure out how to do this in VBScript?

March 4th, 2015 4:08pm

I can't get your method to work.  I'm using a slight modification, as I get a syntax error on the first line when I leave it as "\\.\".

'------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\ccm\ClientSDK")
Set objInstall = GetObject("winmgmts:\\" & strComputer & "\root\ccm\ClientSDK:CCM_SoftwareUpdatesManager")
Set colItems = objWMIService.ExecQuery("SELECT * FROM CCM_SoftwareUpdate WHERE ArticleID=3019215")

For Each objItem In colItems

'Added the Echo to ensure I was getting a result
WScript.Echo "BulletinID: " & objItem.BulletinID

objInstall.InstallUpdates objItem.BulletinID

Next
'------------------

I get "SWbemObjectEx: Type mismatch"

I'm trying to use VBScript (PowerShell isn't an option in my very specific use case) to install one specific SCCM update (I already know the ArticleID).

Free Windows Admin Tool Kit Click here and download it now
March 4th, 2015 5:14pm

The InstallUpdates method expects an array of updates, you're passing a single BulletinID.

Try converting the colItems (which is a collection) into an array and passing the array into the InstallUpdates method.

March 23rd, 2015 5:50pm

Very old topic.  Here is the direction from the documentation.

Set colItems = objWMIService.ExecQuery("SELECT * FROM CCM_SoftwareUpdate WHERE ComplianceState=0)0
resultCode=objInstall.InstallUpdates(colItems)

https://msdn.microsoft.com/en-us/library/jj155394.aspx?f=255&MSPPError=-2147217396

Note the it takes a "collection of CCMUpdates" and not an array of IDs.  The CCM_SoftwareUpdate class returns that collection.

Free Windows Admin Tool Kit Click here and download it now
March 23rd, 2015 6:03pm

jrv,

are you sure passing a collection will do the trick? The documentation says it expects an array of CCM_SoftwareUpdates, not a collection and the two are slightly different.

March 27th, 2015 2:23am

jrv,

are you sure passing a collection will do the trick? The documentation says it expects an array of CCM_SoftwareUpdates, not a collection and the two are slightly different.

In techo-speak an array is a collection.  Look at the definition of the method call.

[IN]  CCM_SoftwareUpdate CCMUpdates[]

It is clearly a collection (array) of "CCMUpdates" type.

Parameters

CCMUpdates[]           
Data type: CCM_SoftwareUpdate

Qualifiers: [in]

Array of software updates that are installed

Free Windows Admin Tool Kit Click here and download it now
March 27th, 2015 10:24am

I agree that an array is a type of collection.

I also agree that the parameter expects an array of CCM_SoftwareUpdates, but there are differences between a collection and an array in VBScript:

You can access a specific position of an array using array(pos), you can't do that in a collection. You can do a UBound(array) on an array, you can't on a collection. You can resize an array, you can't resize a collection, etc etc.

VBScript is not great when it comes to automatically converting composite data types and while I'm not sure whether it will do that with a collection or not nor am I in a position to test it, but I am just pointing out that it MIGHT be needed to convert the collection into an array, as that's what the function expects.

March 27th, 2015 1:12pm

Thanks for the feedback. I think I might be able to test this over the weekend. I will post results. I have to find or deploy a test computer that still has security patches pending.
Free Windows Admin Tool Kit Click here and download it now
March 27th, 2015 7:11pm

I still have not got this to work. I am getting a type mismatch. On one I can get a list of updates, but the install just sits for over an hour with no progress. I will kow more in a couple weeks when the April updates come out.
April 3rd, 2015 4:17pm

Show us your current code.
Free Windows Admin Tool Kit Click here and download it now
April 4th, 2015 10:52am

I am closing this thread. I have other duties that are taking up my time. I never did get to finding an answer.
May 28th, 2015 12:36pm

You have repeatedly failed to post the exact error message and you have not posted the code that causes the error.  How can you expect anyone to help you if you do not provide required information.

You can use PowerShell.  It works on and to all platforms supported by SCCM and WSUS.  You haven't even tried it.

Free Windows Admin Tool Kit Click here and download it now
May 28th, 2015 12:43pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics