Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. function Get-DateRange {
  2. param(
  3. [Parameter(Mandatory = $true)]
  4. [ValidateNotNull()]
  5. [datetime] $StartDate,
  6. $EndDate,
  7.  
  8. [timespan] $Duration,
  9.  
  10. [ValidateNotNull()]
  11. [timespan] $Step = [timespan]::FromDays(1)
  12. )
  13. if ($Duration -ne $null -and $EndDate -ne $null) {
  14. throw 'Can not set both $Duration and $EndDate'
  15. }
  16. if ($EndDate -ne $null) {
  17. $EndDate = [datetime]$EndDate
  18. }
  19. if ($Duration -ne $null) {
  20. $EndDate = $StartDate + $Duration
  21. }
  22. if ($EndDate -eq $null) {
  23. throw 'Must set $Duration or $EndDate'
  24. }
  25. if ($EndDate -le $StartDate) {
  26. throw '$EndDate must be greater than $StartDate'
  27. }
  28.  
  29. $d = $StartDate
  30. while ($d -lt $EndDate) {
  31. $d
  32. $d = $d + $Step
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement