@@ -5,6 +5,8 @@ function Get-NinjaOneLocationBackupUsage {
55 Gets backup usage for a location from the NinjaOne API.
66 . DESCRIPTION
77 Retrieves backup usage for a location from the NinjaOne v2 API. For all locations omit the `locationId` parameter for devices backup usage use `Get-NinjaOneBackupUsage`.
8+ . FUNCTIONALITY
9+ Location Backup Usage
810 . EXAMPLE
911 PS> Get-NinjaOneLocationBackupUsage -organisationId 1
1012
@@ -15,35 +17,45 @@ function Get-NinjaOneLocationBackupUsage {
1517 Gets backup usage for the location with id 1 in the organisation with id 1.
1618 . OUTPUTS
1719 A powershell object containing the response.
20+ . LINK
21+ https://docs.homotechsual.dev/modules/ninjaone/commandlets/Get/Get-NinjaOneLocationBackupUsage
1822 #>
1923 [CmdletBinding ()]
2024 [OutputType ([Object ])]
2125 [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSReviewUnusedParameter' , ' ' , Justification = ' Uses dynamic parameter parsing.' )]
2226 Param (
23- # Organisation ID
24- [Parameter (ValueFromPipelineByPropertyName , Mandatory , Position = 0 )]
27+ # Organisation id to retrieve backup usage for.
28+ [Parameter (Mandatory , Position = 0 , ValueFromPipeline , ValueFromPipelineByPropertyName )]
2529 [Alias (' id' , ' organizationId' )]
2630 [Int ]$organisationId ,
27- # Location ID
28- [Parameter (ValueFromPipelineByPropertyName , Position = 1 )]
31+ # Location id to retrieve backup usage for.
32+ [Parameter (Position = 1 , ValueFromPipelineByPropertyName )]
2933 [Int ]$locationId
3034 )
3135 try {
3236 Write-Verbose ' Getting organisation from NinjaOne API.'
3337 $Organisation = Get-NinjaOneOrganisations - organisationId $organisationId
34- Write-Verbose ' Getting location from NinjaOne API.'
35- if ($locationId ) {
36- $Location = Get-NinjaOneLocations - organisationId $organisationId - locationId $locationId
37- if ($Organisation -and $Location ) {
38- Write-Verbose " Retrieving backup usage for $ ( $Location.Name ) ."
39- $Resource = " v2/organization/$ ( $organisationId ) /locations/$ ( $locationId ) /backup/usage"
38+ if ($Organisation ) {
39+ Write-Verbose ' Getting location from NinjaOne API.'
40+ if ($locationId ) {
41+ $Location = Get-NinjaOneLocations - organisationId $organisationId | Where-Object - Property id -EQ - Value $locationId
42+ if ($Location ) {
43+ Write-Verbose (' Getting backup usage for location {0} in organisation {1}.' -f $location.name , $organisation.name )
44+ $Resource = (' v2/organization/{0}/locations/{1}/backup/usage' -f $organisationId , $locationId )
45+ } else {
46+ throw (' Location with id {0} not found in organisation {1}' -f $locationId , $Organisation.Name )
47+ }
48+ } else {
49+ $Locations = Get-NinjaOneLocations - organisationId $organisationId
50+ if ($Organisation -and $Locations ) {
51+ Write-Verbose (' Getting backup usage for all locations in organisation {0}.' -f $organisation.name )
52+ $Resource = (' v2/organization/{0}/locations/backup/usage' -f $organisationId )
53+ } else {
54+ throw (' Organisation {0} does not have any locations.' -f $Organisation.Name )
55+ }
4056 }
4157 } else {
42- $Location = Get-NinjaOneLocations - organisationId $organisationId
43- if ($Organisation -and $Location ) {
44- Write-Verbose " Retrieving backup usage for all locations for $ ( $Organisation.Name ) ."
45- $Resource = " v2/organization/$ ( $organisationId ) /locations/backup/usage"
46- }
58+ throw (' Organisation with id {0} not found.' -f $organisationId )
4759 }
4860 $RequestParams = @ {
4961 Resource = $Resource
0 commit comments