Parameterized PowerShell AD OU Mover

Parameterized PowerShell AD OU Mover

Writes a reusable parameterized PowerShell script that finds disabled Active Directory users and moves them to a target OU, with WhatIf and logging.

Parameterized PowerShell AD OU Mover

Role

You are a PowerShell automation engineer. You write reusable scripts that operations teams can drop into scheduled tasks without editing source.

Objective

Produce a parameterized PowerShell script that finds disabled AD users and moves them into the target OU supplied via the ${targetOU} variable.

Inputs needed

  • ${targetOU}: distinguished name of the destination OU
  • Schedule context: interactive vs. Task Scheduler vs. CI runner
  • Naming convention for log files
  • Any account exclusions

Output format

  1. Header comments: purpose, parameters, usage, author
  2. param() block: [string]$targetOU (mandatory), [switch]$WhatIf, [string]$LogPath
  3. Module import and input validation (check OU exists)
  4. Query and filter: disabled users minus exclusion list
  5. Loop: Move-ADObject inside try/catch, honor -WhatIf
  6. Structured log output per user: timestamp, SamAccountName, source OU, result
  7. End-of-run summary with counts and exit codes

Constraints

  • Every section has an explanatory comment.
  • Errors never kill the loop; they log and continue.
  • Script must support -WhatIf natively.
  • No hardcoded domain; derive from current session or parameter.

Example (optional)

param(
  [Parameter(Mandatory)][string]$targetOU,
  [switch]$WhatIf
)
Import-Module ActiveDirectory
Get-ADUser -Filter {Enabled -eq $false} | ForEach-Object {
  try {
    Move-ADObject -Identity $_.DistinguishedName -TargetPath $targetOU -WhatIf:$WhatIf
    Write-Host "Moved: $($_.SamAccountName) -> $targetOU"
  } catch { Write-Host "Fail: $($_.SamAccountName) — $_" }
}

© Shen Huang · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 11,971 prompts

More by @OpenSourceBuffGuy

See all
Paris Shopfront Editorial Portrait prompt image

Paris Shopfront Editorial Portrait

Generates a moody film-scanned editorial portrait of a young woman in an oversized leather coat outside a vintage Paris wine shop at dusk.

image-prompt, nano-banana, negative-prompt, portrait, woman, medium-shot, editorial, fashion, film-grain, muted-colors, cinematic, photorealistic, vertical-format, text-rendering, soft-lighting, moody, bokeh, cityscape

Pastel autumn outfit lookbook with handwritten annotations prompt image

Pastel autumn outfit lookbook with handwritten annotations

Creates a pastel e-commerce fashion lookbook poster of a model in a simple autumn outfit, with handwritten labels, arrows and a bold headline.

image-prompt, fashion, fashion-shoot, poster, text-rendering, pastel, autumn, full-body, woman, minimalist, negative-space, vertical-format, gpt-image, product-photography, social-media-graphic, photorealistic, for-online-sellers, for-designers, portrait, editorial, whimsical, cozy, studio-lighting

Premium food photography template prompt image

Premium food photography template

Creates a steaming, glossy spicy Sichuan-style dish photo in a dark bowl with chilies and restaurant props, with the food and ratio left to fill in.

image-prompt, gpt-image, food-photography, photorealistic, cinematic, moody, dramatic-lighting, bokeh, close-up, high-angle, square-format, placeholders, template, negative-prompt, cooking, restaurants, product-photography, for-photographers, for-small-business-owners, for-online-sellers, advertising

Reviews

Loading reviews…

Discussion

Loading comments…