Get-ExampleTimeSeries.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function Get-ExampleTimeSeries {
    [CmdletBinding()]
    param(
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [int]
        $Count = 100
        ,
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [datetime]
        $Start
        ,
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [datetime]
        $End = (Get-Date)
        ,
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [int]
        $IntervalDays = 7
    )

    if (-Not $Start) {
        $Start = $End.AddDays(-1 * $IntervalDays)
    }

    $StartTicks = $Start.Ticks
    $EndTicks = $End.Ticks

    1..$Count | ForEach-Object {
        Get-Random -Minimum $StartTicks -Maximum $EndTicks
    } | Sort-Object | ForEach-Object {
        [pscustomobject]@{
            Timestamp = Get-Date -Date $_
            Value     = Get-Random -Minimum 0 -Maximum 100
        }
    }
}