Outputs/output-json.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
using module "..\MCCA.psm1"

class json : MCCAOutput
{

    $OutputDirectory=$null

    json()
    {
        $this.Name="JSON"
    }

    RunOutput($Checks,$Collection)
    {

        # Write to file

        if($null -eq $this.OutputDirectory)
        {
            $OutputDir = $this.DefaultOutputDirectory
        }
        else 
        {
            $OutputDir = $this.OutputDirectory
        }

        $Tenant = $(($Collection["AcceptedDomains"] | Where-Object {$_.InitialDomain -eq $True}).DomainName -split '\.')[0]
        $ReportFileName = "MCCA-$($tenant)-$(Get-Date -Format 'yyyyMMddHHmm').json"

        $OutputFile = "$OutputDir\$ReportFileName"

        $Result = New-Object -TypeName PSObject -Property @{
            ResultDate=$(Get-Date -format s)
            Tenant=$Tenant
            Results=$Checks
        }

        $Result | ConvertTo-Json -Depth 100 | Out-File -FilePath $OutputFile

        $this.Completed = $True
        $this.Result = $OutputFile

    }

}