Library / Google Workspace

GWS-001 · Script

Organizational Unit Management

Creates, updates, or removes organizational units (OUs) and places users into them from CSV files.

Version 1.0.0Language PowerShellUpdated November 2026

What it does

Reads an OU list and, optionally, a user placement list. Missing OUs are created (including parent OUs), descriptions are updated when they differ, and OUs marked Remove are deleted (Google only allows deleting empty OUs). Users are moved only when they are not already in the target OU. Optionally moves every member of a Google Group into one OU. Preview mode (default) shows every change without making it.

Requirements

GAM7, installed and authorized by you. GAM is not included. Windows PowerShell 5.1 or PowerShell 7.

How to run it

  • Run from: an admin workstation or scheduled task with GAM7 set up
  • This is an admin script for your Google Workspace tenant, not a per-device endpoint script
  • User interaction: none with app-only sign-in
  • Schedule: run on demand, or weekly for reports

Settings

NameWhat it doesOptionsDefault
ModePreview = show changes only (default). Apply = make the changes.Preview, ApplyPreview
OrgUnitCsvCSV with columns: OrgUnitPath, Description (optional), Action (optional: Ensure or Remove; default Ensure).
PlacementCsvCSV with columns: Email, OrgUnitPath.
SourceGroupOptional. Move all user members of this group into -TargetOrgUnit.
TargetOrgUnitThe OU used with -SourceGroup.
GamPathPath to GAM. Default: gam (on PATH).gam

Exit codes

  • 0 = Completed, nothing needs attention
  • 1 = Completed, but some items failed or need attention
  • 2 = Script error (see log)

Testing steps

  1. Run it first with the mode set to Preview on one test account or small group. Nothing is changed in that mode.
  2. Read the log and confirm the planned changes are what you expect.
  3. Run your chosen settings on the same test target and confirm the result.
  4. Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
  5. Roll out to a small group next, then everyone.

Rollback steps

Preview mode changes nothing. The log lists every OU and user change. To undo, run again with a CSV holding the original OU paths. Removed OUs can be created again with the create action.

Version and change log

VersionDateChanges
1.0.0November 2026First release.