Refactor Get-NCScheduledTasks and update access group functions - #5
Conversation
… access group functions, update deprecated PSA endpoint
- Get-NCScheduledTasks: remove unused -All/-PageNumber/-PageSize/-SortBy/-SortOrder
params and make -TaskId mandatory (N-central has no bulk list endpoint)
- New-NCOrgAccessGroup: only include orgUnitIds/userIds in body when provided
- New-NCDeviceAccessGroup: only include deviceIds/userIds in body when provided
- Get-NCStandardPsaCustomerMapping: migrate from deprecated
/api/standard-psa/customer-mapping/{id} to /api/standard-psa/customer/{id}/mappings
… begin/process blocks - Use PascalCase consistently when referencing parameters in body construction and ShouldProcess calls - Fix .PARAMETER casing in comment-based help to match param declarations - Add begin/process blocks to Get-NCFilters, New-NCServiceOrg, New-NCSite - Clean up indentation and remove extra blank lines in process blocks
….json - Add test asserting Get-NCScheduledTasks requires -TaskId - SpecDrift.Tests.ps1: read spec.json from repo root instead of Tests/fixtures/openapi-spec.json to avoid stale fixture drift
There was a problem hiding this comment.
🟡 Changes recommended
The updated SpecDrift test points to a non-existent spec.json, and the new Get-NCScheduledTasks test does not actually validate that -TaskId is mandatory.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the NCRestAPI PowerShell module to v1.8.1 and refactors several cmdlets to improve consistency (parameter casing, lifecycle blocks), remove non-functional parameters, and align a mapping cmdlet with an updated API endpoint. It also updates/extends Pester tests and the changelog to reflect these behavior changes.
Changes:
- Refactors
Get-NCScheduledTasksto require-TaskIdand removes non-working paging/bulk parameters; adds a corresponding test. - Updates
Get-NCStandardPsaCustomerMappingto use the newer/api/standard-psa/customer/{id}/mappingsendpoint. - Standardizes cmdlet structure and parameter casing across multiple cmdlets and adjusts access-group body construction to avoid sending null arrays.
File summaries
| File | Description |
|---|---|
| Tests/SpecDrift.Tests.ps1 | Changes drift test to read a root OpenAPI spec file (currently points to spec.json). |
| Tests/NCRestAPI.Tests.ps1 | Adds a new Pester test intended to enforce Get-NCScheduledTasks -TaskId requirement. |
| Public/New-NCSite.ps1 | Standardizes help parameter casing and refactors to begin/process with cleaner body construction. |
| Public/New-NCServiceOrg.ps1 | Refactors to begin/process and simplifies request body construction and posting. |
| Public/New-NCScheduledTask.ps1 | Standardizes comment-based help .PARAMETER casing. |
| Public/New-NCOrgAccessGroup.ps1 | Avoids sending orgUnitIds/userIds when omitted. |
| Public/New-NCDeviceAccessGroup.ps1 | Avoids sending deviceIds/userIds when omitted. |
| Public/New-NCCustomer.ps1 | Standardizes PascalCase variable references in body construction and ShouldProcess. |
| Public/Get-NCStandardPsaCustomerMapping.ps1 | Updates endpoint path and adjusts verbose logging/help to match. |
| Public/Get-NCScheduledTaskStatus.ps1 | Standardizes comment-based help parameter casing and examples. |
| Public/Get-NCScheduledTasks.ps1 | Removes dead parameters and makes -TaskId mandatory; updates behavior/docs accordingly. |
| Public/Get-NCJobStatus.ps1 | Simplifies endpoint construction/logging and standardizes casing. |
| Public/Get-NCFilters.ps1 | Introduces begin/process for API lifecycle consistency. |
| Public/Get-NCDeviceServices.ps1 | Standardizes help casing and simplifies verbose/endpoint logic. |
| Public/Get-NCDeviceAssets.ps1 | Simplifies endpoint construction and removes redundant variables/returns. |
| Public/Get-NCDefaultDeviceProperty.ps1 | Simplifies endpoint construction/logging and standardizes casing. |
| Public/Get-NCApplianceTask.ps1 | Standardizes comment-based help parameter casing and examples. |
| NCRestAPI.psd1 | Bumps module version to 1.8.1. |
| CHANGELOG.md | Adds 1.8.1 entry documenting the refactors and fixes. |
Review details
- Files reviewed: 19/21 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The access-group body construction now omits explicitly-passed empty arrays and the new scheduled-tasks test doesn’t actually verify -TaskId is mandatory.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (3)
Public/New-NCOrgAccessGroup.ps1:79
- The new conditional
if ($OrgUnitIds)/if ($UserIds)drops the property when the caller passes an empty array (@()), even if they explicitly provided the parameter. If the API distinguishes between “field omitted” vs “empty list”, this becomes a functional behavior change; prefer checking$nullinstead so empty arrays are still sent.
if ($OrgUnitIds) { $body.orgUnitIds = $OrgUnitIds }
if ($UserIds) { $body.userIds = $UserIds }
Public/New-NCDeviceAccessGroup.ps1:73
- The new
if ($DeviceIds)/if ($UserIds)checks treat an explicitly-passed empty array (@()) as false and omit the field entirely. To preserve the ability to send an empty list (and only omit when the parameter is not provided), check for$nullinstead of truthiness.
if ($DeviceIds) { $body.deviceIds = $DeviceIds }
if ($UserIds) { $body.userIds = $UserIds }
Tests/NCRestAPI.Tests.ps1:322
- This test currently throws because
-TaskId ''violatesValidateNotNullOrEmpty(), so it would also have passed before this PR (it doesn’t actually assert that-TaskIdis mandatory). Consider asserting the parameter metadata instead to ensure the cmdlet truly requires-TaskIdwithout risking an interactive prompt.
Describe 'Get-NCScheduledTasks parameter enforcement' {
It 'requires -TaskId (no bulk endpoint)' {
$cmd = Get-Command Get-NCScheduledTasks
$paramAttr = $cmd.Parameters['TaskId'].Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] } | Select-Object -First 1
- Files reviewed: 19/21 changed files
- Comments generated: 1
- Review effort level: Lite
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| if ($null -ne $DeviceIds) { $body.deviceIds = $DeviceIds } | ||
| if ($null -ne $UserIds) { $body.userIds = $UserIds } |
| if ($null -ne $OrgUnitIds) { $body.orgUnitIds = $OrgUnitIds } | ||
| if ($null -ne $UserIds) { $body.userIds = $UserIds } |
There was a problem hiding this comment.
🟢 Approval recommended
Changes are cohesive and covered by updated tests, with only minor maintainability nits noted in the access-group body construction.
Review details
Suppressed comments (2)
Public/New-NCOrgAccessGroup.ps1:79
- These
ifstatements are currently unindented relative to the surrounding code and only check$null -ne .... Prefer$PSBoundParameters.ContainsKey(...)(to only send fields the caller supplied) and indent them to match the rest of the function for readability.
if ($null -ne $OrgUnitIds) { $body.orgUnitIds = $OrgUnitIds }
if ($null -ne $UserIds) { $body.userIds = $UserIds }
Public/New-NCDeviceAccessGroup.ps1:73
- The conditional additions to
$bodyare not indented like the rest of the function and rely only on$null -ne .... Using$PSBoundParameters.ContainsKey(...)makes it explicit that the caller provided the parameter (and keeps behavior consistent with other cmdlets that only send supplied fields), while fixing the indentation/readability issue.
if ($null -ne $DeviceIds) { $body.deviceIds = $DeviceIds }
if ($null -ne $UserIds) { $body.userIds = $UserIds }
- Files reviewed: 19/21 changed files
- Comments generated: 0 new
- Review effort level: Lite
This pull request updates the module to version 1.8.1 and includes several bug fixes, standardizations, and code cleanups across multiple cmdlets. The most significant changes are the removal of dead parameters from
Get-NCScheduledTasks(making-TaskIdmandatory), improved consistency in parameter casing and variable usage, and updates to endpoint usage for some cmdlets. There are also improvements to body construction for group creation cmdlets and consistent use ofbegin/processblocks for API lifecycle management.Cmdlet Parameter and API Usage Fixes:
Get-NCScheduledTasks: Removed unused parameters (-All,-PageNumber,-PageSize,-SortBy,-SortOrder) that previously threw errors;-TaskIdis now mandatory, and the documentation clarifies there is no bulk-list endpoint. Added a test to assert-TaskIdis required. [1] [2]Get-NCStandardPsaCustomerMapping: Updated to use the new endpoint/api/standard-psa/customer/{id}/mappingsinstead of the deprecated one. [1] [2]New-NCOrgAccessGroup/New-NCDeviceAccessGroup: OptionalorgUnitIds/deviceIds/userIdsarrays are only sent if provided (not asnull). [1] [2]Parameter Casing and Consistency:
New-NCCustomer,New-NCSite,New-NCServiceOrg,Get-NCJobStatus,Get-NCDefaultDeviceProperty, and others. [1] [2] [3] [4] [5] [6] [7]Codebase Simplification and Formatting:
Get-NCJobStatus,Get-NCDefaultDeviceProperty,Get-NCDeviceAssets,Get-NCDeviceServices). [1] [2] [3] [4] [5]Lifecycle Management Consistency:
begin/processblocks for API instance lifecycle consistency inGet-NCFilters,New-NCServiceOrg, andNew-NCSite. [1] [2] [3]Testing and Miscellaneous:
SpecDrift.Tests.ps1to read the rootspec.jsoninstead of a fixture file.These changes improve reliability, maintainability, and consistency across the module.