Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Create Session with Exchange 2010 change your URI address
- $s=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://contoso/powershell -Authentication Kerberos
- Import-PSSession -Session $s
- ## Add AD Cmdlets
- Import-Module ActiveDirectory
- #Import CSV
- $csv = @()
- $csv = Import-Csv -Delimiter "," -Path "C:\ADuser.csv"
- #Get Domain Base
- $searchbase = Get-ADDomain | ForEach { $_.DistinguishedName }
- #Loop through all items in the CSV
- ForEach ($user In $csv)
- {
- ## change your OU with your own OU
- $OU = "OU=New Users,OU=Users,OU=employee,DC=Contoso,DC=com"
- $Password = "Abc123+"
- $title= $user.'New Post title'
- $lastname= ($user.'Last name'.Substring(0,1).toupper() + $User.'Last name'.Substring(1).tolower())
- $Detailedname = $User.'First name' + " " + $lastname
- $UserFirstname = $User.'First name'
- $SAM = $User.'First name' + "." + $lastname
- $UPN= $UserFirstname + "." + $lastname + "@contoso.com"
- $ID= $user.ID
- $Displayname= "$Detailedname" + " " + "-" + " " + "$title"
- $Company= "Contoso"
- $Dis= "Contoso User"
- $group= "All Users","All Contoso Users"
- $homedrive= "\\nas1\home\%username%"
- #Check if the User exists
- $NameID = $user.ID
- $User = Get-ADUser -LDAPFilter "(EmployeeID=$NameID)"
- If ($User -eq $Null)
- {
- #Create the User if it doesn't exist
- $create = New-ADUser -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $UPN -DisplayName $Displayname -GivenName $UserFirstname -Surname $lastname -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path $OU -EmployeeID $ID -Title $title -Description $Dis -Company $Company -HomeDrive Z: -HomeDirectory $homedrive -ChangePasswordAtLogon $true
- ## Adding User to Group
- Add-ADPrincipalGroupMembership -Identity $SAM -MemberOf $group
- ## Creating Mailbox on EX2010
- Enable-Mailbox -Identity $SAM -Alias $SAM
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement