ceturtdiena, 2013. gada 28. marts

How to add users to ou in domain via Powershell Windows 2008



Before to use PowerShell you have to allow powershell scripts via policy, while there are lot of policies I just allow scripts on separate DomainController with higher access restritions
So you have to type in  PowerShell terminal

Set-ExecutionPolicy Unrestricted

So here are powershell script itself

Import-Module ActiveDirectory 
$Users = Import-Csv -Delimiter ";" -Path ".\userslist.csv"  
foreach ($User in $Users)  
{  
    $OU = "OU=yourou,DC=yourdomain,DC=comorothersuffix"  
    $Password = $User.password 
echo $Password
    $SPassword = ConvertTo-SecureString $Password -AsPlainText -Force 
echo $SPassword
    $Detailedname = $User.firstname
    $SAM =  $User.Name 
    New-ADUser -Name $Detailedname -SamAccountName $SAM -DisplayName $Detailedname -AccountPassword $SPassword -Enabled $true -Path $OU  


  
I dont know why powershell needs to type column names in lowercase while they are in uppercase
If columnnames are in lowercase it shows error I noticed user are created


Script and csv file could be easy to modify, as you can notice from picture user are added,
you can add fourth column Group and specify group for each user. You can add at the end


    $Group = $User.group
Add-ADGroupMember -Identity $Group -Member $User.Name


On Windows 2003 things are complicated
First you need to install PowerShell on 2003 R2.
DotNetFramework 3.5 and finally
Hotfix KB969429
Now If you want to add users to 2003 R2, you can do it installing special tool from Microsoft site.
Gateway for Windows PowerShell for Windows 2003 R2
http://www.microsoft.com/en-us/download/details.aspx?id=2852

Nav komentāru:

Ierakstīt komentāru