Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-DateRange {
- param(
- [Parameter(Mandatory = $true)]
- [ValidateNotNull()]
- [datetime] $StartDate,
- $EndDate,
- [timespan] $Duration,
- [ValidateNotNull()]
- [timespan] $Step = [timespan]::FromDays(1)
- )
- if ($Duration -ne $null -and $EndDate -ne $null) {
- throw 'Can not set both $Duration and $EndDate'
- }
- if ($EndDate -ne $null) {
- $EndDate = [datetime]$EndDate
- }
- if ($Duration -ne $null) {
- $EndDate = $StartDate + $Duration
- }
- if ($EndDate -eq $null) {
- throw 'Must set $Duration or $EndDate'
- }
- if ($EndDate -le $StartDate) {
- throw '$EndDate must be greater than $StartDate'
- }
- $d = $StartDate
- while ($d -lt $EndDate) {
- $d
- $d = $d + $Step
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement