Creating users via powershell

I am using the windows powershell cmdlets to set up new users automatically 
in AD 2003.  I am particularly using the cmdlets from quest such get-qaduser 
and new-qaduser.  To setup bulk number of users I have to setup a csv file 
and then import them into the script.  The script is below:

#Get-UserGroups.ps1

#sample CSV heading
# 
"Name,Firstname,Lastname,SAMAccountname,Telephone,Office,Department,Title,City,Company"

$file="C:\employees.csv"

if ((Get-Item $file -ea "silentlycontinue" ).exists) {

    Import-Csv $file | ForEach-Object {
        $OU=('OU=' + $_.Department + ',OU=Employees,DC=mycompany,dc=local')

        Write-Host Creating $_.samaccountname -ForegroundColor Green

     New-QADUser -parentcontainer $OU `
        -name ($_.FirstName+' '+$_.LastName) `
        -samAccountName $_.samaccountname -Notes "Imported User Account" `
        -firstname $_.FirstName -lastname $_.LastName `
        -title $_.title -department $_.department -company "mycompany.com" `
        -phonenumber $_.Telephone -userpassword "P@ssw0rd" `
        -office $_.Office -userprincipalname 
($_.samaccountname+'@mycompany.com') `
        -displayname ($_.FirstName+' '+$_.LastName) `
        -City ($_.City) `
        -objectattributes @{"Comment"="created by PowerShell"} |
        Enable-QADUser | Set-QADUser -UserMustChangePassword $True

    }

}
else {

    Write-Host "Can't find $file." -ForegroundColor Red
}


The question I have is that creating a bulk number of users or about few 
users, is creating a csv file and importing into the script the best way to 
do this.  Are there other better methods of creating users via powershell.

Also I want to find out how I can change the above script or if there is 
another script which would ask for parameters such as users name and other 
user parameters and then create the users.  Can anyone advise how I can do 
this. 


0
guv
3/29/2010 2:06:54 PM
windows.powershell 690 articles. 0 followers. Follow

1 Replies
1517 Views

Similar Articles

[PageSpeed] 47

guv wrote:
> I am using the windows powershell cmdlets to set up new users automatically 
> in AD 2003.  I am particularly using the cmdlets from quest such get-qaduser 
> and new-qaduser.  To setup bulk number of users I have to setup a csv file 
> and then import them into the script.  The script is below:
> 
> #Get-UserGroups.ps1
> 
> #sample CSV heading
> # 
> "Name,Firstname,Lastname,SAMAccountname,Telephone,Office,Department,Title,City,Company"
> 
> $file="C:\employees.csv"
> 
> if ((Get-Item $file -ea "silentlycontinue" ).exists) {
> 
>     Import-Csv $file | ForEach-Object {
>         $OU=('OU=' + $_.Department + ',OU=Employees,DC=mycompany,dc=local')
> 
>         Write-Host Creating $_.samaccountname -ForegroundColor Green
> 
>      New-QADUser -parentcontainer $OU `
>         -name ($_.FirstName+' '+$_.LastName) `
>         -samAccountName $_.samaccountname -Notes "Imported User Account" `
>         -firstname $_.FirstName -lastname $_.LastName `
>         -title $_.title -department $_.department -company "mycompany.com" `
>         -phonenumber $_.Telephone -userpassword "P@ssw0rd" `
>         -office $_.Office -userprincipalname 
> ($_.samaccountname+'@mycompany.com') `
>         -displayname ($_.FirstName+' '+$_.LastName) `
>         -City ($_.City) `
>         -objectattributes @{"Comment"="created by PowerShell"} |
>         Enable-QADUser | Set-QADUser -UserMustChangePassword $True
> 
>     }
> 
> }
> else {
> 
>     Write-Host "Can't find $file." -ForegroundColor Red
> }
> 
> 
> The question I have is that creating a bulk number of users or about few 
> users, is creating a csv file and importing into the script the best way to 
> do this.  Are there other better methods of creating users via powershell.

The answer to that is "it depends". If this method works for you then 
all is well. If you were to move away from the CSV file what could you 
use? In the past I've worked for companies that have exported directly 
from an HR database and used that, it all depends on what's available.

> Also I want to find out how I can change the above script or if there is 
> another script which would ask for parameters such as users name and other 
> user parameters and then create the users.  Can anyone advise how I can do 
> this. 

You could use "Read-Host". Personally I don't like scripts that require 
interaction, but that's just me.

Chris
0
Chris
3/31/2010 7:52:46 AM
Reply:

Similar Artilces:

Multiple user names at one bank or brokerage
I have 3 accounts at one bank. I have 3 corresponding accounts set up in MS Money 2007. One of them is setup for online banking while the other two are not. I now want to set the other two up for online banking but I can't find a way to specify the unique login info for each of the other two accounts. ...

Passing login user ID as a parameter using HTML
Hi.. My requirement is to display user specific reports on the custom default home page when the user logs into the CRM application I have a Home page where we display the reports in general (for all users) within frames. We call the RDL reports from SQL Reports using the following sample URL code: "http://<server name>/Reportserver?/Salesreport" for displaying the salesreport. Here "Salesreport" is the RDL file which will take User Id as a parameter. Now My requirement is to pass the login User Id as a parameter to the RDL file When executed the followin...

instructions disppear when users begin type (text field)
Hi all, I need to customize the outlook contact form and I want to add one text field to allow users to add details info and instruct users how to add. Instructions shows in the field and the instructions disappear when users click and begin to type. How should I do this? exchange 2003/outlook2003 Thank you. It's hard for me to visualize exactly what you're expecting to happen. If you want the instructions to stay on the screen, you could display them in a label control. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumps...

Cannot Add Users CRM 4.0 RU 2
I cannot add users to CRM 4.0 after Rollup Update 2. CRM can query the AD and imports the user info, but throws an error when I try to save it. I can however make changes to an existing user and save without a problem. Here is the trace: >MSCRM Error Report: -------------------------------------------------------------------------------------------------------- Error: Exception has been thrown by the target of an invocation. Error Message: Exception has been thrown by the target of an invocation. Source File: Not available Line Number: Not available Request URL: http://**************...

create a boot disk when I have no floppy drive?
I have the XP Upgrade CD. How do I create a boot disk when I have no floppy drive? Thanks for any help. "Bob Tyrka" <rtyrka@cavtel.net> wrote in message news:PPedndBCv5CT7ZjWnZ2dnUVZ_gqdnZ2d@cavtel.net... > I have the XP Upgrade CD. How do I create a boot disk when I have no > floppy drive? > > Thanks for any help. > What do you need a floppy for? The XP CD is bootable in it's own right... "Bob Tyrka" wrote: > I have the XP Upgrade CD. How do I create a boot disk when I have no floppy > drive? > ...

Create Expression from Func? (3.5 SP1)
Hello: Is there are way to create an Expression from a Func? I don't like cluttering up my method signatures with the whole Expression<Func<TResult, T>> type. I would prefer for callers to simply see Func<TResult, T> instead. I'd like to take a Func and create an Expression from it. Is that possible? Thanks, Travis Parks Jehu Galeahsa wrote: > Hello: > > Is there are way to create an Expression from a Func? I don't like > cluttering up my method signatures with the whole > Expression<Func<TResult, T>> type. I would ...

Alert user to check the filed when it is final
Hi, I want to create an alert to check the Final( checkbox ) field, if date_issued is enter. if date_issued is null then do nothing, In what even I have to code this and how? -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201001/1 mls via AccessMonster.com wrote: >Hi, I want to create an alert to check the Final( checkbox ) field, if >date_issued is enter. >if date_issued is null then do nothing, In what even I have to code this and >how? Based on just that one requirement, you can use the date text b...

MS Publisher "Select Table" won't list views with user-defined functions?!
MS Publisher "Select Table" won't list views (queries) containing user-defined functions?! What's wrong? And how to work around this? Using the latest version of Microsoft Publisher and MS Access (2003 sp2 with all latest updates), I am trying to create physical asset labels, with a unique serial number on each label. And in Microsoft Publisher, when I go to "select data source" and select my MS Access database "20060117pst2301pmb primary.mdb" (which generates such serial numbers), I get a popup entitled "Select Table" which lists all its tab...

Last day of posting via Microsoft server
Well, I guess this is the last day of posting via the Microsoft server. http://www.teranews.com/ Your own free account ($3.95 one time setup fee) that allows posting or use public.teranews.com without an account (no posting & speed capped). You can use any standard news client you choose to read and post to any newsgroup. Or Google it: http://groups.google.com/groups/search?hl=en&q=microsoft.public.win98.gen_discussion&qt_s=Search God Bless America, Bill O|||||||O mailto:BillHughes@billhughes.com http://www.billhughes.com/jeep_bookmark.htm "D...

Create Process
if i call fork() / CreateProcess what is/are duplicated? i know that data space is duplicated for sure how about code space? the code space can be shared to save space.... but the new process may need to do rebasing... so...does the code space also shared? thx Action wrote: >if i call fork() / CreateProcess >what is/are duplicated? >i know that data space is duplicated for sure >how about code space? >the code space can be shared to save space.... >but the new process may need to do rebasing... >so...does the code space also shared? There is no fork in Windows. Creat...

viewing a user's email account
I have been charged with reviewing a user's email activity / mailbox for a possible impropriety. Is there a way to do this from exchange, or better yet what is the best way to accomplish this steathfuly? On Mon, 23 Oct 2006 18:20:02 -0700, Rossel1 <Rossel1@discussions.microsoft.com> wrote: >I have been charged with reviewing a user's email activity / mailbox for a >possible impropriety. Is there a way to do this from exchange, or better yet >what is the best way to accomplish this steathfuly? I really hope that the users' employment contract provides for this ...

HOWTO create a Mail Merge Template in MSCRM with multiple child records
Hi, I have created successfully a basic Mail Merge template in MS Word in Dynamics CRM 4.0 for Order Entity. My challenge now is how to design a template that retrieves the order details (product and prices) related to the order record? This sounds like a parent-child template. Any idea? On Jun 2, 1:26=A0pm, "Benjie Fallar III" <bfall...@hotmail.com> wrote: > Hi, > I have created successfully a basic Mail Merge template in MS Word in > Dynamics CRM 4.0 for Order Entity. > My challenge now is how to design a template that retrieves the order > details (prod...

Creating a CFormView application produces errors
Using Visual Studio.Net 2003 I have created a C++ MFC application with Single Document Interface and Document/View support, and have changed the base class for the derived View class to CFormView. All other settings are their defaults. When I compile the source code generated, I get an error stating that the base class CRichEditCntrItem is undefined in the declaration of the CRichEditCntrItem derived class. According to the Help, CRichEditCntrItem requires the header afxrich.h If I add this include into the stdafx.H file and recompile, I get a syntax error in the constructor for the CRic...

Looking for a quick way to create a bunch of labels for annual mailing to diverse contacts
Using Office 2004 (11.2), I have numerous contacts that are part of diverse categories (some have not been categorized yet) I would like to create mailing labels for the annual calendar mailing. As of now I figured out how to select a large number of contacts & mark them as part of the annual card category (Command & click) and go to Word's Data Merge Manager where select the main document & then the address book as a data source. I went to Query Options and selected the category that fits (annual card). Now what? ...

switch users without closing program
Hi, Is there a way to switch profiles without closing Outlook 2002? Thanks, Duane ...

Possible to create a rule to alert on BCC messages?
Using Outlook 2007/Exchange Server 2007 Hello: I sometimes miss that I'm receiving an email as a blind copy. I was hoping to create a rule to alert me when I'm in the BCC field. However, when using the rules wizard, I only see the options regarding my name in the To or CC field. Is there a way to create this that I may be missing? Thank you. In article <#pJLIK1ALHA.4704@TK2MSFTNGP06.phx.gbl>, victoria@dig.com says... > > Using Outlook 2007/Exchange Server 2007 > > Hello: > > I sometimes miss that I'm receiving an email as ...

reconnect to mailbox after Disabling user?
Hello, I was wondering if there is a easier way then to recycle the Exchange Services to renable a mailbox after a users mailbox has been disabled for x amount of time. I want to give access to this mailbox to another user so right now.. I simply go to Mailbox Rights -> (add the user I want to add) -> give allow rights to Read / Full but this requires a recycle of the services. Is there another way without recycling the services? G. On Mon, 23 Aug 2004 11:08:36 -0400, "Just Another Admin" <just@dmin.net> wrote: >Hello, > >I was wondering if there ...

How to create an XML document with XmlTextWriter?
Hi, I'm trying to create an XML document with XMLTextWriter but I want to store it in memory (not write it to a file like so many examples do). I tried the following but with no luck. Should I not user this object for this purpose? Thanks, Dave MemoryStream stm = new MemoryStream() XmlTextWriter writer = new XmlTextWriter(stm, System.Text.Encoding.UTF8) writer.WriteStartDocument() writer.WriteComment("This Is A List of My Books") writer.WriteStartElement("MyBooks") writer.WriteStartElement("Book") writer.WriteAttributeString("ISBN", "1861005...

How to let OWA users to change their password ?
How to let OWA users to change their password ? On Wed, 9 Nov 2005 01:58:03 -0800, "Enid" <Enid@discussions.microsoft.com> wrote: >How to let OWA users to change their password ? There are quite a few steps but if you follow this: http://support.microsoft.com/default.aspx?scid=kb;en-us;297121 carefuly, you'll be ok. Thanks for your information. Follow the document to enable the change password funcation, but got error when using IE6 w/ SP2 to do change password "error number : 5". It is so tricky if using FireFox, the password change is work. Any suggesti...

Create your personal SMS homepage, let friends send FREE text message to your mobile phone by web
Create your personal SMS homepage, let friends send FREE text message to your mobile phone by web Support over 147 countries and ALL languages (unicode encoding) MSG.to provides a unique personal SMS URL for you. It is easy for friends sending text message to you by web. For example, if your name is Lisa, you can register: http://MSG.to/Lisa (you can use this link to see demo) You can also register your mobile phone number as SMS URL like: http://MSG.to/+886913123456 (you can use this link to see demo) Please visit http://msg.to/ for more information. Related keywords: Short Message Serv...

Cannot add user to CRM
I have trouble adding user to the CRM. I have 50 users in AD, however, when it comes to adding user in CRM, I can only choose from 15 of them. I wonder why!? I suppose I should be able to pick from all 50 users whoever is in the AD, right? If anyone have any clue on this problem and give me some feedback, I would surely appreciate that!!! CRM deployment manager will not display certain categories of users - eg if they have been migrated from NT domains or Novel NDS without passwords. Search the group archives for UserAccountControl "Martijn van Halen" <MartijnvanHalen@d...

How do I view my calendar by a label I've created?
I would like to assign label colors to items in my calendars (for home use) and then be able to view my monthly calendar by one label at a time as I choose. Is there anyway to do this? I have gone through all the help menus and can't find anything. I found instructions on how to create a filtered view, but under the instructions, I have no "Add Filtered View" as one of my options. Any suggestions? View | (Arrange By) | Current View | Customize Current VIew | Filter --=20 Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtlefloc...

Virus checking via double-clicking
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel At one time double clicking an Office file icon on the Mac by-passed virus checking. If I double click an Office file icon on my Mac, will Mac Office 2008 check for viruses automatically before opening the file for use by the Office application? On Tue, 2 Jun 2009 09:20:19 -0400, trying_to_work@officeformac.com wrote: > Version: 2008 > Operating System: Mac OS X 10.5 (Leopard) > Processor: Intel > > At one time double clicking an Office file icon on the Mac by-passed virus > checking. If I double cli...

User authentication/protection
I'm a professor and use Excel extensively in my classes. I need to be able to assign Excel projects to my students and have some increased assurance that the students have submitted their own work. I've tried my hand at VBA programming and also simply used track changes. None of these solutions (even the track changes) worked reliably across both mac and pc platforms. I would like some advice about whether what I need from Excel is even possible. I Here's what I need and what I think would work: 1. I'd like to prevent a student from getting someone else's sol...

RMS Integration user access
How can I give users in GP access to the RMS Import (Transactions > Retail Management > RM Import) function? I found KB 900636, but it did not work. I'm using GP10 and HQ & RMS 2.0. Thanks, Jocelyn ...