Functions/Get-MCASReport.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
<#
.Synopsis
    Get-MCASReport retrieves a list of built-in reports from the Cloud App Security tenant.
.DESCRIPTION
    Retrieves a reports list from the built-in reports of an MCAS tenant.
.EXAMPLE
    PS C:\> Get-MCASReport | select FriendlyName,report_category
 
    FriendlyName report_category
    ------------ ---------------
    Privileged Users User Management
    Browser Use Security
    Outbound Sharing by Domain Data Management
    Data Sharing Overview Data Management
    Salesforce Special Privileged Accounts User Management
    Owners of Shared Files Data Management
    Inactive Accounts
 
    This example retrives the reports list, showing the friendly name of the report and its category.
 
.EXAMPLE
    PS C:\> Get-MCASReport | Get-MCASReportContent
 
    This example retrives the reports list and pipes the list into the Get-MCASReportContent command to get the data for each one.
#>
function Get-MCASReport {
    [CmdletBinding()]
    param
    (
        # Specifies the credential object containing tenant as username (e.g. 'contoso.us.portal.cloudappsecurity.com') and the 64-character hexadecimal Oauth token as the password.
        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [System.Management.Automation.PSCredential]$Credential = $CASCredential
    )

    # Get the matching items and handle errors
    try {
        $response = Invoke-MCASRestMethod -Credential $Credential -Path "/cas/api/reports/" -Method Get
    }
    catch {
        throw "Error calling MCAS API. The exception was: $_"
    }

    $response = $response.data

    try {
        $response = $response | Add-Member -MemberType AliasProperty -Name Identity -Value _id -PassThru | ForEach-Object {Add-Member -InputObject $_ -MemberType NoteProperty -Name FriendlyName -Value $ReportsListReverse.Get_Item($_.non_entities_report) -PassThru}
    }
    catch {}
    
    $response
}