Repository navigation
feat: create and update users with New-InforcerUser and Set-InforcerUser - #51
Merged
Merged
Conversation
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>
There was a problem hiding this comment.
🟡 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
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>
There was a problem hiding this comment.
🔵 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
…feature/user-management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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-InforcerUsercreates 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 intoSet-InforcerUser. The password goes only into the request body, never into verbose output or errors.Set-InforcerUserupdates 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 fromGet-InforcerUser.-WhatIfand-Confirm, and need an API client login. With an API key they stop withRequiresApiClient, because the beta API has no equivalent.Invoke-InforcerApiRequestnow treats204 No Contentas success without output, and when an update was only partly applied, the error lists each step (Steps: profile: succeeded; manager: failed (reason)).Not in this pull request
Tested
Tests/V1.UserWrite.Tests.ps1(no network): request bodies, defaults, clearing fields, pipeline,-WhatIf, API-key refusal, 409 and the partial 502.SettingsCatalog.Tests.ps1, real settings data) also fails onmain.scripts/Test-AllCmdlets.ps1: all 23 cmdlets run.🤖 Generated with Claude Code