search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Creating Active Directory User with Powershell
Posted in Windows Powershell | No Comment | 2,769 views | 18/08/2009 12:55

I created this script to create active directory user with Powershell.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function Add-ADUser
{
param ($UserID, $HostID, $CustomerID, $FirstName, $LastName, $Password, $CustomerOU)
 
    $FQDN = (Get-ADInfo).FQDN
    $ADDomain = (Get-ADInfo).Domain
 
    $CheckCustomerOU = Check-CustomerOU -CustomerID "$CustomerID" -CustomerOU "$CustomerOU"
    $CheckHostingOU = Check-HostingOU -HostID "$HostID" -CustomerID "$CustomerID" -CustomerOU "$CustomerOU"
 
    $CustomerOU = [ADSI] "LDAP://OU=$HostID,OU=$CustomerID,$CustomerOU,$FQDN"
    $PrincipalName = $UserID + "@" + $ADDomain
    $AddADUser = $CustomerOU.Create("User","CN=$UserID")
    $AddADUser.Put("GivenName", "$FirstName")
    $AddADUser.Put("SN", "$LastName")
    $AddADUser.Put("Description", "$FirstName $LastName")
    $AddADUser.Put("sAMAccountName", "$UserID")
    $AddADUser.Put("userPrincipalName", "$PrincipalName")
    $AddADUser.Put("DisplayName", "$FirstName $LastName")
    $AddADUser.SetInfo()
    $AddADUser.SetPassword("$Password")
    $AddADUser.SetInfo()
    $AddADUser.Psbase.Invokeset("AccountDisabled", "False")
    $AddADUser.SetInfo()
    $AddADUser.Put("userAccountControl", "66080")
    $AddADUser.SetInfo()
 
    If(!$AddADUser)
    {
        Write-Host "An Error Occurred."
        $Status = "0"
        Return
    }
    $Status = "1"
}

You can find included functions with search.



Leave a Reply