dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.44k stars 796 forks source link

[Set-DbaAgentSchedule] Errors when $null passed for EndDate #9256

Closed lowlydba closed 7 months ago

lowlydba commented 7 months ago

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

End date cannot be before start date 30200525

When a null end date is supplied, it incorrectly tries to check it as being less than the start date. It is missing the first check to see if it is not null before proceeding, like the check above it:

https://github.com/dataplat/dbatools/blob/71920cb9245349581e70a54eed447959a8d34ba1/public/Set-DbaAgentSchedule.ps1#L343-L350

Steps to Reproduce

Set-DbaAgentSchedule -SqlInstance sql1 -Job Job1 -ScheduleName daily -StartDate 20250101 -EndDate $null

Please confirm that you are running the most recent version of dbatools

Major  Minor  Build  Revision
-----  -----  -----  --------
2      1      8      -1

Other details or mentions

No response

What PowerShell host was used when producing this error

PowerShell Core (pwsh.exe)

PowerShell Host Version

Various

SQL Server Edition and Build number

Various

.NET Framework Version

Various