|
| 1 | +Function Get-LMSysOIDMap { |
| 2 | + |
| 3 | + [CmdletBinding(DefaultParameterSetName = 'All')] |
| 4 | + Param ( |
| 5 | + [Parameter(ParameterSetName = 'Id')] |
| 6 | + [Int]$Id, |
| 7 | + |
| 8 | + [Parameter(ParameterSetName = 'Name')] |
| 9 | + [String]$Name, |
| 10 | + |
| 11 | + [Parameter(ParameterSetName = 'Filter')] |
| 12 | + [Object]$Filter, |
| 13 | + |
| 14 | + [ValidateRange(1, 1000)] |
| 15 | + [Int]$BatchSize = 1000 |
| 16 | + ) |
| 17 | + #Check if we are logged in and have valid api creds |
| 18 | + If ($Script:LMAuth.Valid) { |
| 19 | + |
| 20 | + #Build header and uri |
| 21 | + $ResourcePath = "/setting/functions" |
| 22 | + |
| 23 | + #Initalize vars |
| 24 | + $QueryParams = "" |
| 25 | + $Count = 0 |
| 26 | + $Done = $false |
| 27 | + $Results = @() |
| 28 | + |
| 29 | + #Loop through requests |
| 30 | + While (!$Done) { |
| 31 | + #Build query params |
| 32 | + Switch ($PSCmdlet.ParameterSetName) { |
| 33 | + "All" { $QueryParams = "?size=$BatchSize&offset=$Count&sort=+id" } |
| 34 | + "Id" { $resourcePath += "/$Id" } |
| 35 | + "Name" { $QueryParams = "?filter=name:`"$Name`"&size=$BatchSize&offset=$Count&sort=+id" } |
| 36 | + "Filter" { |
| 37 | + #List of allowed filter props |
| 38 | + $PropList = @() |
| 39 | + $ValidFilter = Format-LMFilter -Filter $Filter -PropList $PropList |
| 40 | + $QueryParams = "?filter=$ValidFilter&size=$BatchSize&offset=$Count&sort=+id" |
| 41 | + } |
| 42 | + } |
| 43 | + Try { |
| 44 | + $Headers = New-LMHeader -Auth $Script:LMAuth -Method "GET" -ResourcePath $ResourcePath |
| 45 | + $Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath + $QueryParams |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation |
| 50 | + |
| 51 | + #Issue request |
| 52 | + $Response = Invoke-RestMethod -Uri $Uri -Method "GET" -Headers $Headers[0] -WebSession $Headers[1] |
| 53 | + |
| 54 | + #Stop looping if single device, no need to continue |
| 55 | + If ($PSCmdlet.ParameterSetName -eq "Id") { |
| 56 | + $Done = $true |
| 57 | + Return (Add-ObjectTypeInfo -InputObject $Response -TypeName "LogicMonitor.SysOIDMap") |
| 58 | + } |
| 59 | + #Check result size and if needed loop again |
| 60 | + Else { |
| 61 | + [Int]$Total = $Response.Total |
| 62 | + [Int]$Count += ($Response.Items | Measure-Object).Count |
| 63 | + $Results += $Response.Items |
| 64 | + If ($Count -ge $Total) { |
| 65 | + $Done = $true |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + Catch [Exception] { |
| 70 | + $Proceed = Resolve-LMException -LMException $PSItem |
| 71 | + If (!$Proceed) { |
| 72 | + Return |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + Return (Add-ObjectTypeInfo -InputObject $Results -TypeName "LogicMonitor.SysOIDMap") |
| 77 | + } |
| 78 | + Else { |
| 79 | + Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again." |
| 80 | + } |
| 81 | +} |
0 commit comments