From 59022dcd5d446024c1e47cd3c2f8e960082739e3 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 13 Feb 2021 02:20:33 -0600 Subject: [PATCH 1/3] Implemented sliding function to enumerate all apps --- Functions/Get-MCASDiscoveredApp.ps1 | 38 ++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/Functions/Get-MCASDiscoveredApp.ps1 b/Functions/Get-MCASDiscoveredApp.ps1 index 13e471d..4954417 100644 --- a/Functions/Get-MCASDiscoveredApp.ps1 +++ b/Functions/Get-MCASDiscoveredApp.ps1 @@ -59,6 +59,11 @@ function Get-MCASDiscoveredApp { [ValidateNotNullOrEmpty()] [int]$ResultSetSize = 100, + # Specifies the maximum number of results to retrieve when listing items matching the specified filter criteria. Set to 100 by default. + [Parameter(ParameterSetName='List', Mandatory=$false)] + [ValidateNotNullOrEmpty()] + [Switch]$All, + # Specifies the number of records, from the beginning of the result set, to skip. Set to 0 by default. [Parameter(ParameterSetName='List', Mandatory=$false)] [ValidateScript({$_ -gt -1})] @@ -209,22 +214,33 @@ function Get-MCASDiscoveredApp { #endregion ----------------------------FILTERING---------------------------- + region ----------------------------PARSING---------------------------- + function Get-Response($restResponse){ + try { + Write-Verbose "Adding alias property to results, if appropriate" #but why + $parsedresponse = $restResponse | Add-Member -MemberType AliasProperty -Name Identity -Value 'appId' -PassThru + } + catch {} + $parsedresponse + } + #endregion ----------------------------PARSING---------------------------- try { - #$response = Invoke-MCASRestMethod -Credential $Credential -Path "/cas/api/discovery/" -Method Post -Body $body #-FilterSet $filterSet - $response = Invoke-MCASRestMethod -Credential $Credential -Path "/cas/api/v1/discovery/discovered_apps/" -Method Post -Body $body -FilterSet $filterSet + if ($All){ + $body.limit = 100 + do{ + $rawresponse = Invoke-MCASRestMethod -Credential $Credential -Path "/api/v1/discovery/discovered_apps/" -Method Post -Body $body -FilterSet $filterSet + $response += $rawresponse.data + $body.skip += 100 + } while ($response.count % 100 -eq 0) + } + else{ + $rawresponse = Invoke-MCASRestMethod -Credential $Credential -Path "/api/v1/discovery/discovered_apps/" -Method Post -Body $body -FilterSet $filterSet + $response = $rawresponse.data + } } catch { throw "Error calling MCAS API. The exception was: $_" } - - $response = $response.data - - try { - Write-Verbose "Adding alias property to results, if appropriate" - $response = $response | Add-Member -MemberType AliasProperty -Name Identity -Value 'appId' -PassThru - } - catch {} - $response } \ No newline at end of file From 136b07a43ec6a637c9622bcdf9e2e39a19f23002 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 13 Feb 2021 02:22:19 -0600 Subject: [PATCH 2/3] Removed parsing function --- Functions/Get-MCASDiscoveredApp.ps1 | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Functions/Get-MCASDiscoveredApp.ps1 b/Functions/Get-MCASDiscoveredApp.ps1 index 4954417..0bc1f20 100644 --- a/Functions/Get-MCASDiscoveredApp.ps1 +++ b/Functions/Get-MCASDiscoveredApp.ps1 @@ -214,16 +214,6 @@ function Get-MCASDiscoveredApp { #endregion ----------------------------FILTERING---------------------------- - region ----------------------------PARSING---------------------------- - function Get-Response($restResponse){ - try { - Write-Verbose "Adding alias property to results, if appropriate" #but why - $parsedresponse = $restResponse | Add-Member -MemberType AliasProperty -Name Identity -Value 'appId' -PassThru - } - catch {} - $parsedresponse - } - #endregion ----------------------------PARSING---------------------------- try { if ($All){ From 058733c1928eddecd4a6c17506b73f6da591d590 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 13 Feb 2021 02:25:58 -0600 Subject: [PATCH 3/3] Updated documentation and added example --- Functions/Get-MCASDiscoveredApp.ps1 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Functions/Get-MCASDiscoveredApp.ps1 b/Functions/Get-MCASDiscoveredApp.ps1 index 0bc1f20..b253b68 100644 --- a/Functions/Get-MCASDiscoveredApp.ps1 +++ b/Functions/Get-MCASDiscoveredApp.ps1 @@ -16,6 +16,20 @@ Retrieves the first 5 app names sorted alphabetically. +.EXAMPLE + PS C:\> Get-MCASDiscoveredApp -All -StreamId $streamid | select name + + name + ---- + 1ShoppingCart + ABC News + ACTIVE + AIM + AT&T + ... + + Retrieves all app names + .EXAMPLE PS C:\> Get-MCASDiscoveredApp -StreamId $streamid -Category SECURITY | select name,@{N='Total (MB)';E={"{0:N2}" -f ($_.trafficTotalBytes/1MB)}} @@ -59,7 +73,7 @@ function Get-MCASDiscoveredApp { [ValidateNotNullOrEmpty()] [int]$ResultSetSize = 100, - # Specifies the maximum number of results to retrieve when listing items matching the specified filter criteria. Set to 100 by default. + # Specifies to retrieve all apps that match filters [Parameter(ParameterSetName='List', Mandatory=$false)] [ValidateNotNullOrEmpty()] [Switch]$All,