Skip to content

feat: create and update users with New-InforcerUser and Set-InforcerUser - #51

Merged
royklo merged 3 commits into
api-drift/2026-11-10-0922from
feature/user-management
Nov 10, 2026
Merged

royklo merged 3 commits into
api-drift/2026-11-10-0922from
feature/user-management

Conversation

@royklo

@royklo royklo commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Why

The API adds two user actions on v1: create a user and update a user. This adds them to the module, on top of the API-change pull request #50.

What changes

  • New-InforcerUser creates a Microsoft Entra user. Required: tenant, display name, user principal name and a password (SecureString). By default the user can sign in and must change the password at the first sign-in; the mail alias defaults to the part of the UPN before the @. Returns the new user's id with the tenant, display name and UPN, so it can be piped into Set-InforcerUser. The password goes only into the request body, never into verbose output or errors.
  • Set-InforcerUser updates a user's profile, manager or sign-in. Only the parameters you pass are sent; every other field stays as it is. '' (or @() for lists) clears a field, for example -ManagerId '' removes the manager. Display name, mail alias, UPN and mail cannot be cleared, so an empty value is refused. Users can be piped in from Get-InforcerUser.
  • Both cmdlets support -WhatIf and -Confirm, and need an API client login. With an API key they stop with RequiresApiClient, because the beta API has no equivalent.
  • Invoke-InforcerApiRequest now treats 204 No Content as success without output, and when an update was only partly applied, the error lists each step (Steps: profile: succeeded; manager: failed (reason)).
  • Docs: cmdlet reference, API reference (endpoints, permissions, schemas), README and module README. The exact write grant of "User & Group Management" is marked unconfirmed.

Not in this pull request

  • Version bump and CHANGELOG entry: they belong to the release.
  • A live test against the API.

Tested

  • 14 new mocked tests in Tests/V1.UserWrite.Tests.ps1 (no network): request bodies, defaults, clearing fields, pipeline, -WhatIf, API-key refusal, 409 and the partial 502.
  • Full suite: 867 passed, 1 failed. The failure (SettingsCatalog.Tests.ps1, real settings data) also fails on main.
  • scripts/Test-AllCmdlets.ps1: all 23 cmdlets run.

🤖 Generated with Claude Code

The v1 API adds POST /tenants/{msTenantId}/users and PATCH
/tenants/{msTenantId}/users/{userId}. Both cmdlets need an API client
login; an API-key (beta) session stops with RequiresApiClient because
beta has no equivalent.

New-InforcerUser sends the required fields with safe defaults (sign-in
enabled, password change at first sign-in, mail alias from the UPN) and
returns the new id with the tenant, display name and UPN so it pipes
into Set-InforcerUser. The password goes only into the request body.

Set-InforcerUser sends only the parameters that were passed (JSON Merge
Patch); '' or an empty array clears a field, and the four fields the API
cannot clear refuse an empty value. Users pipe in by id.

Invoke-InforcerApiRequest now treats 204 as success without output and
adds a problem+json results[] list to the error text, so a partly
applied update says which step failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Transport failures can leave the plaintext initial password in request content retained by error records, requiring shared cleanup and regression coverage for those records.

1 open issue
What changed in this PR

Adds v1 user creation and updates to the module through New-InforcerUser and Set-InforcerUser, extending the existing user retrieval functionality.

Changes:

  • Adds API-client-only write cmdlets with pipeline support, -WhatIf, and -Confirm.
  • Handles successful empty responses and reports individual steps in partially applied updates.
  • Adds mocked tests, command exports, output formatting, and user-management documentation.
File Description
Tests/​V1.UserWrite.Tests.ps1 Tests request bodies, defaults, clearing fields, pipeline input, and errors.
Tests/​Consistency.Tests.ps1 Adds both cmdlets to the export and parameter contracts.
scripts/​Test-AllCmdlets.ps1 Adds smoke-check invocations for both cmdlets.
README.md Lists the new user-management cmdlets.
module/​README.md Updates the public cmdlet inventory.
module/​Public/​Set-InforcerUser.ps1 Adds selective user updates and field clearing.
module/​Public/​New-InforcerUser.ps1 Adds user creation with secure-string password input.
module/​Private/​Invoke-InforcerApiRequest.ps1 Handles HTTP 204 and partial-update error details.
module/​Private/​ConvertTo-InforcerUserBody.ps1 Builds request bodies from explicitly bound fields.
module/​InforcerCommunity.psd1 Exports both new cmdlets.
module/​InforcerCommunity.Format.ps1xml Adds the created-user display format.
docs/​CMDLET-REFERENCE.md Documents parameters, examples, and login requirements.
docs/​API-REFERENCE.md Documents write endpoints, schemas, and unconfirmed permissions.

Review effort: Balanced

Comment thread module/Public/New-InforcerUser.ps1 Resolved
A failed web call keeps the disposed request on its ErrorRecord, and
the disposed body's bytes stay in memory, reachable by reflection: for
New-InforcerUser that is the initial password. Clear-InforcerRequestCredential
already strips the auth headers from that request; it now also zeroes the
body bytes, so every request path is covered. The regression test fails
without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Linked PR #50 reports only a partial API rollout, leaving the deployed user-write endpoints and required grants unverified and requiring maintainer confirmation before merging or releasing.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@royklo
royklo merged commit ecf73c4 into api-drift/2026-11-10-0922 Nov 10, 2026
@royklo
royklo deleted the feature/user-management branch November 10, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants