Functions/Get-MCASIPTag.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
function Get-MCASIPTag{
    [CmdletBinding()]
    param
    (
        # Specifies the CAS credential object containing the 64-character hexadecimal OAuth token used for authentication and authorization to the CAS tenant.
        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [System.Management.Automation.PSCredential]$Credential = $CASCredential,

        # Specifies the maximum number of results to retrieve when listing items matching the specified filter criteria.
        [Parameter(Mandatory=$false)]
        [ValidateRange(1,100)]
        [int]$ResultSetSize = 100,

        # Specifies the number of records, from the beginning of the result set, to skip.
        [Parameter(Mandatory=$false)]
        [ValidateScript({$_ -ge 0})]
        [int]$Skip = 0
    )
    process {

        # Get the matching alerts and handle errors
        try {
            $response = Invoke-MCASRestMethod -Credential $Credential -Path "/cas/api/tags/?enabledOnly=true&sort=name&sortDirectory=asc&target=ip" -Method Get # IP tag
        }
        catch {
            throw "Error calling MCAS API. The exception was: $_"
        }

        Write-Verbose "Getting just the response property named 'data'"
        $response = $response.data

        try {
            Write-Verbose "Adding alias property to results, if appropriate"
            $response = $response | Add-Member -MemberType AliasProperty -Name Identity -Value '_id' -PassThru
        }
        catch {}

        $response
    }
}