spjeff / sppatchify

SharePoint Patchify - centralized tool to apply CU patch to entire farm from one console
MIT License
1 stars 0 forks source link

enforce statements to return an array (always) #31

Closed malterad closed 4 years ago

malterad commented 4 years ago

Hi Jeff, a happy New Year!

I had to limit $maxWorkers to 1 to deal with my badly equiped database instance, else all but the first database upgrade failed. However, when doing so, I learned that e.g. Where-Object returns an array only if there are more than one match. But it returns an OBJECT if there is just one match. So statements like ($active.Count -lt $maxWorkers) don't work in that case.

The best solution I found here: https://stackoverflow.com/questions/11107428/how-can-i-force-powershell-to-return-an-array-when-a-call-only-returns-one-objec and states that one should wrap the command in @(...) to enforce getting an array (an empty, one-element or multi-element array).

As I had trouble with that in the UpgradeContent function, I have listed only the occurrences in this function, which may require a wrapping of the statements in @(...). There are more lines where this approach may make sense.

https://github.com/spjeff/sppatchify/blob/bb77918cc823d016abdfbdfcc6b904468336efe2/SPPatchify.ps1#L982 https://github.com/spjeff/sppatchify/blob/bb77918cc823d016abdfbdfcc6b904468336efe2/SPPatchify.ps1#L1004 https://github.com/spjeff/sppatchify/blob/bb77918cc823d016abdfbdfcc6b904468336efe2/SPPatchify.ps1#L1055 https://github.com/spjeff/sppatchify/blob/bb77918cc823d016abdfbdfcc6b904468336efe2/SPPatchify.ps1#L1068

Besides that: it would be great, if maxWorkers is a parameter of the script (can default to 4). I have never seen a trustable calculation how many upgrades can be done in parallel, so I wonder if the limitiation can actually be calculated (or tested).

Regards Malte

spjeff commented 4 years ago

Excellent suggestion Malterad. Updated code.

https://github.com/spjeff/sppatchify/commit/fbe7bb4a5c27d94f9f511a8cafe2365aaa0852f2#diff-5918760c8d2458204dcbb74d9364e7d7