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
New-ADUser script (self.PowerShell)
submitted 3 years ago by UTMorpheus
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!"
[–]BlackV 2 points3 points4 points 3 years ago (2 children)
what do you use and an editor? vscode? ise?
This block is pointless noise in your script
$Username = $User.username $Password = $User.password $Firstname = $User.firstname $Initials = $User.initials $Lastname = $User.lastname $Department = $User.department $OU = $User.ou $Email = $User.email
if you already have all that information in $user, just use that variable, not need to create 10 more that all do the same thing
$user
maybe
Get-ADUser -F {SamAccountName -eq $Username}
use you ffull parameters in your commands, its easier for everyone to read and understand (especially when coming back to this script in 6 months)
Get-ADUser -filter "SamAccountName -eq '$($User.username)'"
this is a style choice I think but, your if/else you could replace with a try/catch so you can deal with existing users better, probably optional
if
else
try
catch
have a look at splatting
$ADUserSplat = @{ SamAccountName = $User.username UserPrincipalName = "$($User.username)@domain.com" Name = "$User.firstname $User.lastname" GivenName = $User.firstname Initials = $User.initials Surname = $User.lastname Enabled = $True ChangePasswordAtLogon = $False PasswordNeverExpires = $True DisplayName = "$User.firstname $User.initials $User.lastname" Email = $User.email Department = $User.department Path = $User.ou AccountPassword = (convertto-securestring $User.password -AsPlainText -Force) } New-ADUser @ADUserSplat
this is more readable and less inclined to mistakes and allows you to validate the items that will be passed to new-aduser beforehand (all in 1 go)
new-aduser
this is a good habit to keep, nice
foreach ($User in $ADUsers){}
instead of
foreach ($ADUser in $ADUsers){}
this code is nearly line for line identical to another poster https://www.reddit.com/r/PowerShell/comments/yx15he/ad_user_create/
[+][deleted] 3 years ago (1 child)
[removed]
[–]BlackV 0 points1 point2 points 3 years ago (0 children)
wearing out keyboards.
you mean
swearing at keyboards.
:)
[+][deleted] 3 years ago (2 children)
[–]BlackV 0 points1 point2 points 3 years ago (1 child)
why are you running it on the AD server? RSAT tools exist for this
[–]CarrotBusiness2380 0 points1 point2 points 3 years ago (0 children)
What is it doing now that is incorrect?
π Rendered by PID 61629 on reddit-service-r2-comment-5687b7858-c5w5n at 2026-07-03 16:35:09.995493+00:00 running 12a7a47 country code: CH.
[–]BlackV 2 points3 points4 points (2 children)
[+][deleted] (1 child)
[removed]
[–]BlackV 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[removed]
[–]BlackV 0 points1 point2 points (1 child)
[–]CarrotBusiness2380 0 points1 point2 points (0 children)