none
Windows Server 2008 R2: Script create multi users with Windows Powershell

    问题

  • Dear All,

    I have windows server 2008 R2 Active Directory Domain Service. I want to create multi users by using Windows PowerShell.

    Could you guide?

    BR,

    Khemarin Set


    Khemarin333@hotmail.com
    2011年8月18日 1:12

答案

全部回复

  • Here are a couple of examples:

    http://techstarts.wordpress.com/2007/02/21/bulk-user-creation-using-powershell-2/

    http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/57e3cac9-a4d0-4857-b862-ca814d5e5873/

    For PowerShell related questions, you might want to refer to the Powershell Technet forum...

    hth
    Marcin

    2011年8月18日 1:15
  • Script Repository with numerous examples on how to create users in bulk: http://gallery.technet.microsoft.com/ScriptCenter/en-us/
    If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".

    Rich Prescott | MCITP, MCTS, MCP

    Blog | Twitter: @Arposh | Powershell Client System Administration tool
    2011年8月18日 1:24
  • You can refer powershell script below too.

    http://www.telnetport25.com/2011/04/creating-lab-users-with-a-powershell-script/

    Regards  


    Awinish Vishwakarma

    MVP-Directory Services

    MY BLOG:  http://awinish.wordpress.com

    This posting is provided AS-IS with no warranties/guarantees and confers no rights.

    2011年8月18日 3:49
    版主
  • Dear Awinish,

    Your link very my solution. but i'm very basic with Powershell and I never have experience with it.

     

    This is the link original script that you are provide:

    function Select-FileDialog 

    {

    param([string]$Title,[string]$Directory,[string]$Filter="CSV Files (*.csv)|*.csv")

    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null

    $objForm = New-Object System.Windows.Forms.OpenFileDialog

    $objForm.InitialDirectory = $Directory

    $objForm.Filter = $Filter

    $objForm.Title = $Title

    $objForm.ShowHelp = $true

    $Show = $objForm.ShowDialog()

    If ($Show -eq "OK")

    {

    Return $objForm.FileName

    }

    Else

    {

    Exit

    }

    }

    $FileName = Select-FileDialog -Title "Import an CSV file" -Directory "C:"

    $ExchangeUsersOU = "OU=ExchangeUsers" # I don understand, I have all users are store in all-users ou

    $domain = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()

    $DomainDN = (([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Domains | ? {$_.Name -eq $domain}).GetDirectoryEntry().distinguishedName

    $final = "LDAP://$DomainDN"

    $DomainPath = [ADSI]"$final"

    $cOU = $DomainPath.Create("OrganizationalUnit",$ExchangeUsersOU)

    $cOU.SetInfo()

     

    $UserInformation = Import-Csv $FileName

     

    $OUPath = "LDAP://$ExchangeUsersOU,$DomainDN" # I don understand

    $UserPath = [ADSI]"$OUPath"

    Write-Host "---------------------------------------------------------------"

    Write-Host "Creating LAB Users"

    Write-Host ""

    Write-Host "---------------------------------------------------------------"

     

    Foreach ($User in $UserInformation){

    $CN = $User.samAccountName

    $SN = $User.Surname

    $Given = $User.givenName

    $samAccountName = $User.samAccountName

    $Display = $User.DisplayName

    $LABUser = $UserPath.Create("User","CN=$CN")

    Write-Host "Creating User: $User.samAccountName"

    $LABUser.Put("samAccountName",$samAccountName)

    $LABUser.Put("sn",$SN)

    $LABUser.Put("givenName",$Given)

    $LABUser.Put("displayName",$Display)

    $LABUser.Put("mail","$samAccountName@$domain")

    $LABUser.Put("description", "Lab User - created via Script")

    $LABUser.Put("userPrincipalName","$samAccountName@$domain")

    $LABUser.SetInfo()

     

    $Pwrd = $User.Password

    $LABUser.psbase.invoke("setPassword",$Pwrd)

    $LABUser.psbase.invokeSet("AccountDisabled",$False)

    $LABUser.psbase.CommitChanges()

    }

    Write-Host "Script Completed"

    If posible, could you help to correct script as: I have domain name: hello.net. All user are store in all-users ou.

    BR,

    Khemarin Set


    Khemarin333@hotmail.com
    2011年8月18日 4:37
  • You don't have to do anything inside the powershell script, extract the files.  To run the script you open PowerShell and navigate to the location of the script and type .\CreateUsersFromCSV.ps1 This will open a dialog for you to locate the CSV file & you need to actually modify the csv file & then you can move the use wherever you want. Once you choose the CSV it will create the users and place them in an Organizational Unit called ExchangeUsers & you can change the OU to some other. Test in a lab first.

     

    Regards  


    Awinish Vishwakarma

    MVP-Directory Services

    MY BLOG:  http://awinish.wordpress.com

    This posting is provided AS-IS with no warranties/guarantees and confers no rights.

    2011年8月18日 5:17
    版主
  • Thanks so much.

    It's working well.

    BR,

    Khemarin Set


    Khemarin333@hotmail.com
    2011年8月18日 6:29
  • Glad to help you & thanks for the update.

     

    Regards  


    Awinish Vishwakarma

    MVP-Directory Services

    MY BLOG:  http://awinish.wordpress.com

    This posting is provided AS-IS with no warranties/guarantees and confers no rights.

    2011年8月18日 6:30
    版主
  • Thank you it works for me. 

    Ashane Deshapriya ( MCP )

    2014年4月5日 19:40