Public/MIA/Get-MIAReport.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function Get-MIAReport
{
    [CmdletBinding(DefaultParameterSetName='TaskRun')]
    param (
        # Default to a TaskRun report if no parameters are specified. Even though
        # the switch if false, it is only used to select the correct
        # parameter set.
        [Parameter(Mandatory=$false,
                    ParameterSetName='TaskRun')]
        [switch]$TaskRun=$false,

        [Parameter(Mandatory,
                    ParameterSetName='FileActivity')]
        [switch]$FileActivity,

        [Parameter(Mandatory,
                    ParameterSetName='Audit')]
        [switch]$Audit,

        [Parameter(Mandatory=$false)]
        [string]$Predicate = '',

        [Parameter(Mandatory=$false)]
        [string]$OrderBy = '',

        [Parameter(Mandatory=$false)]
        [int32]$MaxCount = 100

    )

    switch ($PSCmdlet.ParameterSetName)
    {
        'TaskRun' {
            if ('' -eq $Predicate) {
                $Predicate = 'Status=in=("Success","Failure")'
            }

            if ('' -eq $OrderBy) {
                $OrderBy = '!StartTime'
            }

            $query = @{
                predicate = "$Predicate";
                orderBy = "$OrderBy";
                maxCount = "$MaxCount"
            }

            $response = Invoke-MIARequest -Resource 'reports/taskruns' -Method 'Post' -Body $query
            Write-MIAOutput -Response $response -Typename 'MIREST.MIAReportTaskRun'
        }

        'FileActivity' {
            if ('' -eq $Predicate) {
                $Predicate = 'StatusCode=out=("5000","5010")'
            }

            if ('' -eq $OrderBy) {
                $OrderBy = '!LogStamp'
            }

            $query = @{
                predicate = "$Predicate";
                orderBy = "$OrderBy";
                maxCount = "$MaxCount"
            }

            $response = Invoke-MIARequest -Resource 'reports/fileactivity' -Method 'Post' -Body $query
            Write-MIAOutput -Response $response -Typename 'MIREST.MIAReportFileActivity'
        }

        'Audit' {
            if ('' -eq $Predicate) {
                $Predicate = 'Status=="Failure"'
            }

            if ('' -eq $OrderBy) {
                $OrderBy = '!LogTime'
            }

            $query = @{
                predicate = "$Predicate";
                orderBy = "$OrderBy";
                maxCount = "$MaxCount"
            }

            $response = Invoke-MIARequest -Resource 'reports/audit' -Method 'Post' -Body $query
            Write-MIAOutput -Response $response -Typename 'MIREST.MIAReportAudit'
        }
    }

}