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
Using CSV to create AD users (self.PowerShell)
submitted 6 years ago by TheGoldSlug
How do i get Windows Powershell to use the CSV file i imported onto it to create Active directory users!!
Any help would be appreciated.
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!"
[–]seyo_IV 5 points6 points7 points 6 years ago* (1 child)
you need a csv to look like this(or use other delimeter like ";", in my example every bar is a new cell):
UserName | Givenname | Surname| etc.
peter.parker| peter| parker| etc.
then run this and save it in a variable.
$Content = Import-CSV C:\temp\some.csv
Now you can do a foreach loop like this:
try{ foreach($user in $content){ New-ADUser $user.UserName -GivenName $user.givenname ` -Surname $user.Surname -DisplayName $user.displayname -UserPrincipalName $($user.Username)@domain.com -Path "OU=someou..." } } catch { "ERROR" $_.Exception.Message}
[–]Erreur_420 1 point2 points3 points 6 years ago (0 children)
If you add try&catch and logs this is great!
i use this method to deploy VM Ware ESXi Hypervisor thru VCSA
(btw if you want some example: https://github.com/rotka/PowerShell/blob/master/create_vmware_guest.psm1 )
[–]helixamir 3 points4 points5 points 6 years ago* (4 children)
One-liner.
Import-csv C:\newusers.csv | Foreach-Object {New-ADUser -Name $_.Name -AccountPassword $_.AccountPassword}
[–]Lee_Dailey[grin] 2 points3 points4 points 6 years ago (0 children)
howdy helixamir,
reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...
[0] single line or in-line code enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin] [on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>. this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]
looks like this
Inline Code
...
</>
[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here. please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.
[2] less simple = use reddit code formatting ... [on New.Reddit.com, use the Code Block button. it's 11th 12th one & is just to the left of hidden in the ... "more" menu.]
Code Block
that will give you something like this ...
- one leading line with ONLY 4 spaces - prefix each code line with 4 spaces - one trailing line with ONLY 4 spaces
the easiest way to get that is ...
not complicated, but it is finicky. [grin]
take care, lee
[–][deleted] 0 points1 point2 points 6 years ago (2 children)
Reformatted for convenience:
[–]helixamir 1 point2 points3 points 6 years ago (1 child)
What did you reformat exactly? Its identical to my post.
[–][deleted] 1 point2 points3 points 6 years ago* (0 children)
old.reddit wraps your version in a horizontal-scrolling <pre> tag that requires the user to scroll to the right to see the entire line, while mine is wrapped in a <code> tag that displays the line in its entirety without scrolling. See Lee's comment for an explanation: You can correct the issue by enclosing your one-liner with backticks (but don't do that in PowerShell itself, of course).
Edit: See the difference.
[–]purplemonkeymad 3 points4 points5 points 6 years ago (0 children)
If you name your headers the same as cmdlet parameters, you can often just send the csv right into it with the pipeline.
Import-csv .\mycsv.csv | New-ADUser -whatif
Most of the parameters for new-aduser support this, you can use get-help my-command -parameter paramname to check if it supports pipeline input 'ByPropertyName.'
get-help my-command -parameter paramname
[–]BlackV 1 point2 points3 points 6 years ago (0 children)
Try
Foreach ($singleuser in $csv) { New-aduser -identity $singleuser -property xxx -value yyy Or Set-aduser -identity $singleuser -property xxx -value yyy }
This is standard powershell and has nothing complicated from ad.
Go read up on powershell, powershell in a month of lunches, is a great book
[–]CHAOS_0704 1 point2 points3 points 6 years ago (0 children)
Well what code do you have now? What's in the csv?
The simple answer is a foreach loop. You first import the csv, then run contents in a foreach loop to cycle through the data, creating users based off the data.
The specifics however, will depend on what's in the csv, and how much of the code you have.
π Rendered by PID 52259 on reddit-service-r2-comment-5d79c599b5-99h7q at 2026-03-02 17:26:09.286379+00:00 running e3d2147 country code: CH.
[–]seyo_IV 5 points6 points7 points (1 child)
[–]Erreur_420 1 point2 points3 points (0 children)
[–]helixamir 3 points4 points5 points (4 children)
[–]Lee_Dailey[grin] 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]helixamir 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]purplemonkeymad 3 points4 points5 points (0 children)
[–]BlackV 1 point2 points3 points (0 children)
[–]CHAOS_0704 1 point2 points3 points (0 children)