Created
June 10, 2015 03:14
-
-
Save gabrielrojas/c1fe45015d12b4e7bd65 to your computer and use it in GitHub Desktop.
Create User in Active Directory and Exchange. Applies to Exchange 2010 and AD 2012 or higher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Creates new user in Active Directory based on Company Standards | |
.DESCRIPTION | |
Import module from Active Directory and Exchange withou the need to have the tools the installed on the computer running the commands | |
I will communicate with AD 2012 R2 and Exchange 2010 | |
.EXAMPLE | |
New-HPDCUSER -Firstname John -LastName Doe -Password SUperSecretPassword | |
#> | |
function New-CompanyUser | |
{ | |
[CmdletBinding()] | |
Param | |
( | |
# First Name | |
[Parameter(Mandatory=$true)] | |
[string]$FirstName, | |
# Last Name | |
[Parameter(Mandatory=$true)] | |
[string]$LastName, | |
#PAswword | |
[Parameter(Mandatory=$true)] | |
[string]$Password | |
) | |
Begin | |
{ | |
$ActiveDirectory = New-PSSession -ComputerName fileserver | |
Import-Module ActiveDirectory -PSSession $ActiveDirectory -Prefix RM | |
$EXchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://myexchangesererver.company.local/PowerShell/ -Authentication Kerberos | |
Import-PSSession $ExchangeSession -Prefix RM | |
} | |
Process | |
{ | |
$ou = 'OU=Users,OU=MyBusiness,DC=compny,DC=local' | |
$FullName = $FirstName + ' ' + $LastName | |
$SAM = $FirstName[0] | |
$SAM = $SAM + $LastName | |
$Password1 = ConvertTo-SecureString $Password -AsPlainText -Force | |
$UPN = $SAM + '@company.local' | |
$Path = "\\Yourfileserver\userprofiles\$SAM" | |
$Mailbox = 'Mailbox1001' | |
#Creates user in Active Directory | |
New-RMADUser -Name $FullName -DisplayName $FullName -GivenName $FirstName -Surname $LastName -Path $ou -AccountPassword $Password1 -PasswordNeverExpires $true -SamAccountName $SAM -UserPrincipalName $UPN -ProfilePath $Path | |
Add-RMADGroupMember 'SpecialGroup' $sam | |
Set-RMADUser $SAM -Enabled $true | |
#Creates Mailbox | |
Enable-RMMailbox -Identity $SAM -Database $Mailbox | |
} | |
End | |
{ | |
Get-PSSession |Remove-PSSession | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment