Skip to content

Commit 6b60304

Browse files
committed
v2 partial conversion.
1 parent 0d5d8d4 commit 6b60304

94 files changed

Lines changed: 1053 additions & 631 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"cSpell.words": [
3+
"Analyzer",
34
"commandlet",
45
"commandlets",
6+
"Gavsto",
57
"Mikey"
68
]
79
}

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Changelog
22

3+
## 2023-10-31 - Version 2.0.0-beta1
4+
35
## 2023-10-25 - Version 1.12.3
46

57
* Fix broken template policy id parameter handling in `New-NinjaOneOrganisation`.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using namespace System.Management.Automation
2+
class ValidateNodeRoleId : ValidateEnumeratedArgumentsAttribute {
3+
[void]ValidateElement($Element) {
4+
if (-not($Element -eq [String]'auto' -or $Element -is [Int])) {
5+
throw [MetadataException]::new("Value '$Element' is not one of 'auto' or an integer.")
6+
}
7+
}
8+
}

NinjaOne.psd1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = '.\NinjaOne.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.12.3'
15+
ModuleVersion = '2.0.0'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -33,7 +33,7 @@
3333
Description = 'This module provides an interface to the NinjaOne API.'
3434

3535
# Minimum version of the PowerShell engine required by this module
36-
PowerShellVersion = '7.0'
36+
PowerShellVersion = '5.1'
3737

3838
# Name of the PowerShell host required by this module
3939
# PowerShellHostName = ''
@@ -269,10 +269,10 @@
269269
IconUri = 'https://pbs.twimg.com/profile_images/1452496768030187521/kIGQii5Y_400x400.jpg'
270270

271271
# ReleaseNotes of this module
272-
ReleaseNotes = 'Fix broken template policy id parameter handling in New-NinjaOneOrganisation.'
272+
ReleaseNotes = 'PowerShell 5, various bugfixes and enhancements.'
273273

274274
# Prerelease string of this module
275-
# Prerelease = 'Beta1'
275+
Prerelease = 'Beta1'
276276

277277
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
278278
# RequireLicenseAcceptance = $false

PSScriptAnalyzerSettings.psd1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,16 @@
4444
'PSUseCorrectCasing',
4545
'PSUseDeclaredVarsMoreThanAssignments',
4646
'PSUsePSCredentialType',
47-
'PSUseShouldProcessForStateChangingFunctions'
47+
'PSUseShouldProcessForStateChangingFunctions',
48+
'PSUseSingularNouns',
49+
'PSUseLowerCaseForBooleanVariables',
50+
'PSUseLowerCaseForBuiltInFunctions',
51+
'PSUseLowerCaseForParameters',
52+
'PSUseTitleCaseForNonConstants',
53+
'PSUseTitleCaseFunctionNames',
54+
'PSUseTitleCaseVerbs',
55+
'PSUseTitleCaseForCmdletParameters',
56+
'PSUseTitleCaseForConstants'
4857
)
4958
Rules = @{
5059
PSPlaceOpenBrace = @{

Public/Find/Find-NinjaOneDevices.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ function Find-NinjaOneDevices {
66
Searches for devices from the NinjaOne API.
77
.DESCRIPTION
88
Retrieves devices from the NinjaOne v2 API matching a search string. Cannot be used with client credentials authentication at present.
9+
.FUNCTIONALITY
10+
Devices
911
.EXAMPLE
1012
PS> Find-NinjaOneDevices -limit 10 -searchQuery 'ABCD'
1113
@@ -16,6 +18,8 @@ function Find-NinjaOneDevices {
1618
Returns an array of device objects matching the query.
1719
.OUTPUTS
1820
A powershell object containing the response.
21+
.LINK
22+
https://docs.homotechsual.dev/modules/ninjaone/commandlets/find/find-ninjaonedevices
1923
#>
2024
[CmdletBinding()]
2125
[OutputType([Object])]
@@ -24,14 +28,14 @@ function Find-NinjaOneDevices {
2428
# Limit number of devices to return.
2529
[Int]$limit,
2630
# Search query
27-
[Parameter( Mandatory = $True )]
31+
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
2832
[Alias('q')]
2933
[String]$searchQuery
3034
)
3135
$CommandName = $MyInvocation.InvocationName
3236
$Parameters = (Get-Command -Name $CommandName).Parameters
3337
try {
34-
Write-Verbose "Searching for upto $($Limit) devices matching $($Query)"
38+
Write-Verbose ('Searching for upto {0} devices matching {1}.') -f $limit, $searchQuery
3539
$QSCollection = New-NinjaOneQuery -CommandName $CommandName -Parameters $Parameters
3640
$Resource = 'v2/devices/search'
3741
$RequestParams = @{

Public/Get/Backup/Get-NinjaOneLocationBackupUsage.ps1

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Public/Get/Devices/Get-NinjaOneDeviceCustomFields.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function Get-NinjaOneDeviceCustomFields {
55
Gets device custom fields from the NinjaOne API.
66
.DESCRIPTION
77
Retrieves device custom fields from the NinjaOne v2 API.
8+
.FUNCTIONALITY
9+
Device Custom Fields
810
.EXAMPLE
911
PS> Get-NinjaOneDeviceCustomFields
1012
@@ -31,20 +33,21 @@ function Get-NinjaOneDeviceCustomFields {
3133
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = 'Uses dynamic parameter parsing.')]
3234
Param(
3335
# Device id to get custom field values for a specific device.
34-
[Parameter(ValueFromPipelineByPropertyName)]
36+
[Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
3537
[Alias('id')]
3638
[Int]$deviceId,
3739
# Inherit custom field values from parent location and/or organisation.
38-
[Parameter(ValueFromPipelineByPropertyName)]
3940
[Switch]$withInheritance
4041
)
4142
try {
4243
if ($deviceId) {
4344
Write-Verbose 'Getting device from NinjaOne API.'
4445
$Device = Get-NinjaOneDevices -deviceID $deviceId
4546
if ($Device) {
46-
Write-Verbose "Retrieving custom fields for device $($Device.SystemName)."
47-
$Resource = "v2/device/$($deviceId)/custom-fields"
47+
Write-Verbose ('Getting custom fields for device {0}.' -f $Device.Name)
48+
$Resource = ('v2/device/{0}/custom-fields' -f $deviceId)
49+
} else {
50+
throw ('Device with id {0} not found.' -f $deviceId)
4851
}
4952
} else {
5053
Write-Verbose 'Retrieving all device custom fields.'

Public/Get/Devices/Get-NinjaOneDeviceDisks.ps1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function Get-NinjaOneDeviceDisks {
55
Gets device disks from the NinjaOne API.
66
.DESCRIPTION
77
Retrieves device disks from the NinjaOne v2 API.
8+
.FUNCTIONALITY
9+
Device Disks
810
.EXAMPLE
911
PS> Get-NinjaOneDeviceDisks -deviceId 1
1012
@@ -19,25 +21,23 @@ function Get-NinjaOneDeviceDisks {
1921
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = 'Uses dynamic parameter parsing.')]
2022
Param(
2123
# Device id to get disk information for.
22-
[Parameter(ValueFromPipelineByPropertyName, Mandatory)]
24+
[Parameter(Mandatory, Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
2325
[Alias('id')]
2426
[Int]$deviceId
2527
)
2628
$CommandName = $MyInvocation.InvocationName
2729
$Parameters = (Get-Command -Name $CommandName).Parameters
2830
# Workaround to prevent the query string processor from adding an 'deviceid=' parameter by removing it from the set parameters.
29-
if ($deviceId) {
30-
$Parameters.Remove('deviceId') | Out-Null
31-
}
31+
$Parameters.Remove('deviceId') | Out-Null
3232
try {
3333
$QSCollection = New-NinjaOneQuery -CommandName $CommandName -Parameters $Parameters
34-
if ($deviceId) {
35-
Write-Verbose 'Getting device from NinjaOne API.'
36-
$Device = Get-NinjaOneDevices -deviceID $deviceId
37-
if ($Device) {
38-
Write-Verbose "Retrieving disk drives for $($Device.SystemName)."
39-
$Resource = "v2/device/$($deviceId)/disks"
40-
}
34+
Write-Verbose 'Getting device from NinjaOne API.'
35+
$Device = Get-NinjaOneDevices -deviceID $deviceId
36+
if ($Device) {
37+
Write-Verbose ('Getting disks for device {0}.' -f $Device.Name)
38+
$Resource = ('v2/device/{0}/disks' -f $deviceId)
39+
} else {
40+
throw ('Device with id {0} not found.' -f $deviceId)
4141
}
4242
$RequestParams = @{
4343
Resource = $Resource

Public/Get/Devices/Get-NinjaOneDeviceLastLoggedOnUser.ps1

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function Get-NinjaOneDeviceLastLoggedOnUser {
55
Gets device last logged on user from the NinjaOne API.
66
.DESCRIPTION
77
Retrieves device last logged on user from the NinjaOne v2 API.
8+
.FUNCTIONALITY
9+
Device Last Logged On User
810
.EXAMPLE
911
PS> Get-NinjaOneDeviceLastLoggedOnUser -deviceId 1
1012
@@ -19,25 +21,21 @@ function Get-NinjaOneDeviceLastLoggedOnUser {
1921
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = 'Uses dynamic parameter parsing.')]
2022
Param(
2123
# Device id to get the last logged on user for.
22-
[Parameter(ValueFromPipelineByPropertyName, Mandatory)]
24+
[Parameter(Mandatory, Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
2325
[Alias('id')]
2426
[Int]$deviceId
2527
)
2628
$CommandName = $MyInvocation.InvocationName
2729
$Parameters = (Get-Command -Name $CommandName).Parameters
2830
# Workaround to prevent the query string processor from adding an 'deviceid=' parameter by removing it from the set parameters.
29-
if ($deviceId) {
30-
$Parameters.Remove('deviceID') | Out-Null
31-
}
31+
$Parameters.Remove('deviceID') | Out-Null
3232
try {
3333
$QSCollection = New-NinjaOneQuery -CommandName $CommandName -Parameters $Parameters
34-
if ($deviceId) {
35-
Write-Verbose 'Getting device from NinjaOne API.'
36-
$Device = Get-NinjaOneDevices -deviceID $deviceId
37-
if ($Device) {
38-
Write-Verbose "Retrieving last logged on user for $($Device.SystemName)."
39-
$Resource = "v2/device/$($deviceId)/last-logged-on-user"
40-
}
34+
Write-Verbose 'Getting device from NinjaOne API.'
35+
$Device = Get-NinjaOneDevices -deviceID $deviceId
36+
if ($Device) {
37+
Write-Verbose ('Getting last logged on user for device {0}.' -f $Device.Name)
38+
$Resource = ('v2/device/{0}/last-logged-on-user' -f $deviceId)
4139
}
4240
$RequestParams = @{
4341
Resource = $Resource

0 commit comments

Comments
 (0)