How would you structure PowerShell for joiners, movers, and leavers?

November 18, 2026 4 answers
Asked by c.483+ferrulecaddy

HR provides a CSV export, and our current script has repeated blocks for creating accounts, setting attributes, and managing groups. Changes are getting hard to maintain, especially when someone moves departments and needs their old access removed.

Would you split this into functions, run it on a schedule, or use another tool? I'm looking for a practical starting point.

Answers

r.572!quendavo

I'd separate the HR import from the account actions. Have one part read and validate the CSV, then pass a normalized person record to functions for creating an account, updating attributes, and reconciling access. Put the department-to-role and role-to-group mappings in data rather than copying group logic into each workflow.

For a mover, calculate the groups the new role requires and compare them with the groups the automation is responsible for. Add the missing ones and remove obsolete managed ones. Keep a clear boundary around manually assigned or exceptional access so the script doesn't remove it by accident.

Start with a report or preview of the proposed changes, especially removals. Once the mappings and exceptions look right, you can decide whether to run it manually or schedule it.

m.731!zelvori:

That managed-group boundary matters. A department change doesn't necessarily explain every group a person belongs to, so exceptions need an owner and a way to review them.

Reply to this answer
_p68~zaldrix.4

Don't build the whole thing around the assumption that the HR export is always clean. Check required fields, identify records consistently, and flag missing or conflicting information before changing accounts. A tidy script won't fix bad source data.

Log what was proposed, what succeeded, and what failed so someone can investigate without guessing. A manually triggered run is perfectly reasonable while you're getting the process into shape.

Reply to this answer
_h42+torvexa.6

For leavers, write the checklist before writing the code. Disabling an account is only one possible step. Depending on your environment and policies, you may also need to revoke sessions, remove privileged roles and group access, and handle the mailbox.

Make failures visible and give the team a way to rerun or complete missed steps. Also agree with HR on when the process should take effect and who is authorized to request it.

Reply to this answer
Vexlano.7q

It's worth pricing an identity governance tool alongside the PowerShell work. Products such as midpoint, SailPoint, and One Identity may be worth evaluating, and Adaxes offers a web interface for approval or termination workflows.

That doesn't mean a product will cover every local rule without custom work. Compare the licensing, setup, approvals, exception handling, and ongoing support against what your team can maintain. Even a small team can use that comparison to make a budget case.

_y48~ferrulebadge.6:

I'd include orphaned accounts and access reviews in that comparison too. Provisioning is useful, but governance covers more than getting the initial groups right.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions