A few times a year, the first of the month will be a Tuesday. This will cause the fourth Monday to be AFTER the fourth Tuesday. Because of this, you may want to do this:
(Get-Date -Date $patchTuesday).AddDays(13)
This will ensure that you always sync two weeks after patch Tuesday.
In December, this line is going to break in one of two ways...
You are going to end up getting January 1st of the current year, rather than next year
$now.Month + 1 will equal 13, which will cause Get-Date to throw an error
Rather than manually checking for any of these, I would just use Get-Date and not specify a year (it will use the current year by default). That will wrap into next year if appropriate. It would probably end up something like this:
3
u/happysysadm Jun 07 '18
Any improvement to the script is welcome.