Public/Get/Entities/Get-NinjaRMMSoftwareProducts.ps1
#Requires -Version 7 function Get-NinjaRMMSoftwareProducts { <# .SYNOPSIS Gets software products from the NinjaRMM API. .DESCRIPTION Retrieves software products from the NinjaRMM v2 API. .OUTPUTS A powershell object containing the response. #> [CmdletBinding( DefaultParameterSetName = 'Multi' )] [OutputType([Object])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = 'Uses dynamic parameter parsing.')] Param( # Device ID [Parameter(ValueFromPipelineByPropertyName)] [Alias('id')] [Int]$deviceID ) $CommandName = $MyInvocation.InvocationName $Parameters = (Get-Command -Name $CommandName).Parameters try { $QSCollection = New-NinjaRMMQuery -CommandName $CommandName -Parameters $Parameters if ($deviceID) { Write-Verbose 'Getting device from NinjaRMM API.' $Device = Get-NinjaRMMDevices -deviceID $deviceID if ($Device) { Write-Verbose "Retrieving software products for $($Device.SystemName)." $Resource = "v2/device/$($deviceID)/software" } } else { Write-Verbose 'Retrieving all software products.' $Resource = 'v2/software-products' } $RequestParams = @{ Method = 'GET' Resource = $Resource QSCollection = $QSCollection } $SoftwareProductResults = New-NinjaRMMGETRequest @RequestParams Return $SoftwareProductResults } catch { $ErrorRecord = @{ ExceptionType = 'System.Exception' ErrorRecord = $_ ErrorCategory = 'ReadError' BubbleUpDetails = $True CommandName = $CommandName } New-NinjaRMMError @ErrorRecord } } |