|
Guy recommends : View the effective permissions for a folder or shared drive. Free download try it now! |
PowerShell Import-CsvPowerShell's Import-Csv with New-QADUser
|
||||||||||||
| Name | sAMAccountName |
| Bush | gbush |
| Obama | bobama |
| Clinton | hclinton |
Note 8: The first row holds the vital property names. You could think of these 'fields', as LDAP properties, or import-Csv parameters.

SolarWinds' Network Performance Monitor will help you discover what's happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
Download a free trial of Solarwinds' Network Performance Monitor

In the master plan we will employ the import-Csv cmdlet to read the spreadsheet. Then we will feed in the values held in the columns, so that they become the properties of the new-QADUser.
Preparation: Edit $OuBorn. The value of 'OU=PowerShell,DC=cp2,DC=Mosel' will not work with your domain.
Where is the path to your spreadsheet? Edit $Freshmen.
# PowerShell script create users in a named OU
# Author: Guy
Thomas
# Version 2.4 August 2008 tested on PowerShell v 1.0
$OuBorn = 'OU=PowerShell,DC=cp2,DC=Mosel'
$Freshmen =
'E:\powershell\QAD\bunch4.csv'
import-csv $Freshmen |`
where
{new-QADUser -ParentContainer $OuBorn `
-name $_.name -sAMAccountName
$_.sAMAccountName}
Note 9: The two crucial cmdlets are: import-Csv and new-QADUser. Observe how PowerShell pipes the output of import-Csv into new-QADUser. Incidentally, (|) is an important method in PowerShell, learn it here and employ this pipe in future scripts.
Note 10: I have introduced two variables, $OuBorn and $Freshmen. To be brutally honest, the script will not work unless you change the values held by these $Variables to reflect your environment.
Note 11: $_. is a special PowerShell variable which says, 'In this stream', hence $_.name means use the name column from the spreadsheet. I hope that you can now see the importance of the first row in your .csv file.
Note 12: Observe the backtick (`). Perhaps the best way of seeing what this word-wrap symbol achieves is to remove it, and type the command all on one line:
import-csv $Freshmen | where {new-QADUser -ParentContainer $OuBorn -name $_.name -sAMAccountName $_.sAMAccountName}

Import users from a spreadsheet. Just provide a list of the users with their fields in the top row, and save as .csv file. Then launch this FREE utility and match your fields with AD's attributes, click and import the users.
Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.
If you need more comprehensive application analysis software,
Download a free trial of SAM (Server & Application Monitor)
My speciality is getting you started. Once you can create a basic user, then it will be a labour of love to research more properties to include in your spreadsheet. For example, if you have a real-life task of creating dozens of users, then adding values for LastName, and UserPrincipalName would result in better users! See more examples of PowerShell Import-CSV
Two more things that you might like to do with your users
For example:
# PowerShell script create users in a named OU
# Author: Guy
Thomas
# Version 2.4 August 2008 tested on PowerShell v 1.0
$OuBorn = 'OU=PowerShell,DC=cp2,DC=Mosel'
$Freshmen =
'E:\powershell\QAD\bunch4.csv'
import-csv $Freshmen |`
where
{new-QADUser -ParentContainer $OuBorn `
-name $_.name -sAMAccountName
$_.sAMAccountName `
; enable-QADUser $_.name }
Tip: Try an Export-Csv for a user that you created manually in Active Directory User and Computers. Then research the LDAP names in the first row. Naturally, the more property boxes that you add information, the more sense that you can make of the resulting export.
In order to import user accounts into active directory you need to be multi-talented. In addition to PowerShell skills, you need to be a veteran of spreadsheets and a professor of LDAP properties. What makes a difficult task achievable is the QADUser object which you obtain with the QAD snap-In.
If you like this page then please share it with your friends
• PowerShell Home • Quest QAD • QADUser • QADGroup • QADComputer
• Export-CSV • Import CSV • QAD Password • Add-PSSnapin • Free Import User CSVDE Tool
• Get-AdUser -filter • Windows PowerShell • Windows PowerShell .Net
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.

You get 36 topics organized into these 3 sections:
1) Getting Started
2) Real-life tasks
3) Examples of Syntax.
In addition to the ebook, you get a PDF version of this Introduction to PowerShell ebook It runs to 120 pages of A4.
*
Custom Search
|
Guy Recommends: WMI Monitor for Powershell
|
|
Author: Guy Thomas Copyright © 1999-2013 Computer Performance LTD All rights reserved. Please report a broken link, or an error to: | |