Powershell – SCCM and WSUS issues

Let me try to explain my problem. I have an offline system (several servers virtually and physically) that comes with updates via SCCM. We receive updates on a regular basis from a higher department. The content is copied via robocopy and the metadata is imported via WSUSUTIL.exe.

The problem is that the content is reduced via a script (presumably) by the department, so we have more metadata than real files.
This brings us to a lot of problems when you try to download a Softwareupdate group. A manual is provided to filter out the updates that are not included. This is a tedious and not always reliable way.

I do not know if there are technical or organizational difficulties that have made things as they are, but I'm afraid I will not change that.

I have however had an idea on how to automatically get all the updates I have as a file.

Start code

$ list = [System.Collections.ArrayList] @ ()

$ Finalist = [System.Collections.ArrayList] @ ()


net use Z: \  / persistent: no


Select-FolderDialog Function
{
param ([string]$ Description = "Select a folder",[string]$ RootFolder = "Office")

     [System.Reflection.Assembly]:: LoadWithPartialName ("System.windows.forms") |
Out-Null

$ objForm = New-Object System.Windows.Forms.FolderBrowserDialog
$ objForm.Rootfolder = $ RootFolder
$ objForm.Description = $ Description
$ Show = $ objForm.ShowDialog ()
If ($ Show -eq "OK")
{
Returns $ objForm.SelectedPath
}
Other
{
Write-Error "Operation canceled by the user."
}
}

$ Folder = Select-FolderDialog

$ updates1 = get-childitem -path $ folder -file -r
$ updates = $ Updates1.name                                                      


[void][reflection.assembly]:: loadwithpartialname ("Microsoft.Updateservices.administration")

$ updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope

$ updatescope.FromArrivalDate = [datetime]"31/12/2018"



$ Getupdate = (get-wsusserver) .getupdates ($ updatescope)

foreach ($ Update in $ Getupdate)
{

$ cab = $ update.getinstallableitems (). files.fileuri.segments | select-object -last 1
foreach ($ item in $ updates) {if ($ item -eq $ cab) {$ list = $ list + $ Update.id.updateid}}

}
import module "d: " SCCMServer " ConfigurationManager.psd1 & # 39;
cd S01:
$ Softwareupdates = get-cmsoftwareupdate -datepostedmin "31.12.2018"

foreach ($ Softwareupdate in $ Softwareupdates) {
Unique = Softwareupdate.CI_UniqueID
foreach ($ li in $ list) {
if ($ li -eq $ Unique) {$ Finallist = $ Finallist + $ Softwareupdate.CI_ID}
}

}
New-CMSoftwareUpdateGroup -name "Test" -UpdateId $ Finallist                

End of code

The idea is that I collect all the file names, content that I have, that I run on the WSUS server, so that I can understand the unique identifier. Then I run the unique IDs on the SCCM in order to get the IDs with which I can create a group of software updates. Up to here the theory.

If I run the script, I get about 800 update files. This gives about 250 Uniqe_IDs, which gives about 35 IDs for the SCCM. When I try to download them, I will encounter a download error.

If my logic was correct, it should not have happened, right?

Is my logic correct? or was it bad coding, since iam no Powershell expert?

Thank you for your opinion and sorry for the complicated code training, as well as my bad English.

Have a good day