I recently built a function in PS that collections critical/security and application updates from Windows 10/2016 machines. The issue I’m encountering is that my output is generating duplicate KB’s. I’ve tried using Select-Object -Property Name -Unique (Sort-Object as well) to remove the duplicates and the outputs generates a different result.
If anyone has any feedback on how to get the duplicates removed, it would be greatly appreciated.
So, the reason why Select-Object -Property Name -Unique isn’t doing what you want is that you’re limiting the output to just the Name property. I’m assuming you still need some of the other properties. If you’d select ALL of the properties you need, you’d probably be okay, assuming that duplicate entries are 100% duplicates across all properties.
You’re taking a very programmer-y approach, rather than a more PowerShell pipeline-oriented approach; is that mandatory? Your current approach is going to kind of limit you in terms of what you can do “inline” since the C#-style methods you’re using don’t expose all of PowerShell’s functionality.
The approach is not mandatory at all. I don’t have any C# knowledge and didn’t realize that was the approach I was taking. Based on what you suggested, I’ve modified and tested this code and it is now giving the output I’m looking for.
Those .ForEach() and .Where() methods are cute, but they’re really their to entice C# people, in my mind. There are some minor performance differences, but sticking with a fully pipelined approach, for me, provides a lot more flexibility because I can drag in commands for which a cute method doesn’t exist. This approach also works in older versions of PowerShell, where the .ForEach() and .Where() method doesn’t exist.