I'm using the wuapi
to write a script that scans, downloads, and installs updates for a machine that is not connected to the Internet. I have most of this script completed, but I need to be able to do a cast (I believe) to a different object.
I found code here that does exactly what I need, but in C#:
WUApiLib IUpdateInstaller2 yields Error; Some OS updates install others throw HResult -2145124318
And here is what the code looks like:
var collection = new UpdateCollection();
IList<string> updateFiles = Directory.GetFiles(updateFolder);
var fileCollection = new StringCollection();
foreach (var file in updateFiles)
fileCollection.Add(file);
//Error happens here on certain updates. Not all.
/** THIS LINE BELOW IS THE ONE I NEED **/
((IUpdate2)update.BundledUpdates[0]).CopyToCache(fileCollection);
collection.Add(update);
return collection;
The line ((IUpdate2)update.BundledUpdates[0]).CopyToCache(fileCollection);
returns an IUpdate
object, but in order to use the CopyToCache
function, it needs to be an IUpdate2
object. I just can't seem to figure out how to get this part working as powershell gives me a "load library" type of error.
Does anyone know how I can do this in PowerShell?