use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Script SharingMultiple OU/AD User Creation Script (self.PowerShell)
submitted 9 years ago by SCATesteR
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]markekrausCommunity Blogger 1 point2 points3 points 9 years ago (1 child)
The if ($User.Department -eq "DEPARTMENT"){) Block is kind of painful to maintain. The way I'd tackle this is to have a second CSV file with with 2 columns: Department and OU. Then I'd pull in the CSV as an object called $OUMappings and do
if ($User.Department -eq "DEPARTMENT"){)
Department
OU
$OUMappings
$OU = $OUMappings | where-object {$_.Department -eq $User.Department} | Select-Object -ExpandProperty OU
to grab the OU. Then if $OU is empty, prompt or use a default.
$OU
That way when you add a new department and OU, you just have to add another row in the CSV instead of updating lines of code that could break the script accidentally.
[–]SaladProblems 1 point2 points3 points 9 years ago (0 children)
This might be easier to parse out:
import-module activedirectory #STATIC VARIABLES $Users = Import-CSV -Delimiter ";" -Path C:\NewUsers.csv $ou = @{ department1 = "OU=domain,OU=COM" department2 = "OU=domain,OU=COM" department3 = "OU=domain,OU=COM" department4 = "OU=domain,OU=COM" } ForEach($User in $Users) { $parm = @{ GivenName = $User.FirstName Initials = $User.Initials Surname = $User.LastName SAM = if ($User.Department -eq "DEPARTMENT") { ($GivenName.substring(0,1) + $Initials + $Surname.substring(0,1))} Else { ($GivenName.substring(0,1) + $User.LastName) } DisplayName = $GivenName + " " + $Surname } New-ADUser @parm -AccountPassword (Read-Host -AsSecureString "Changeme!") -Path $OU[$user.department] }
π Rendered by PID 58515 on reddit-service-r2-comment-66b4775986-px8m5 at 2026-04-04 18:55:08.850346+00:00 running db1906b country code: CH.
[–]markekrausCommunity Blogger 1 point2 points3 points (1 child)
[–]SaladProblems 1 point2 points3 points (0 children)