Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $UserCredential = Get-Credential
- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
- Import-PSSession $Session
- $first = read-Host 'First Name:'
- $last = read-Host 'Last Name:'
- $Description = read-host 'Title:'
- $Office = read-Host 'Department:'
- $Phone = read-Host 'Cell or Extension Number:'
- $un = read-Host 'Username:'
- $PlainPassword = Read-Host 'Secure Password with at least 8 characters, one number or symbol. Case sensitive:'
- $pw = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force
- $Name = $first + ' ' + $last
- $homedr = 'P:'
- $Homedir = '\server\userdirs\' + $un
- new-ADUser $name -Enabled $true -AccountPassword $pw -Path 'OU=whatever,DC=domain,DC=local' -Department $Office -Description $Description -DisplayName $name -HomeDirectory $Homedir -Manager $Manager -Office $Office -ScriptPath $logon -Title $Description -OfficePhone $Phone -SamAccountName $un -GivenName $first -Surname $last -OtherAttributes @{userprincipalname="$un@domain.local";mail="$un@domain.com";proxyaddresses="SMTP:$un@domain.com";targetaddress="SMTP:$un@domain.onmicrosoft.com";mobile="$Phone"} -passwordneverexpires 1
- set-aduser -Identity $un -homedrive $homedr add-ADGroupMember 'DomainGroup' -Members $un add-ADGroupMember $Office -Members $un
- $message = "Please select an option. Use UPPER CASE LETTER!"
- $city1 = New-Object System.Management.Automation.Host.ChoiceDescription "&city1","Add City1 info"
- $city2 = New-Object System.Management.Automation.Host.ChoiceDescription "&city2","Add City2 info"
- $field = New-Object System.Management.Automation.Host.ChoiceDescription "&field","Add field info"
- $options = [System.Management.Automation.Host.ChoiceDescription[]]($city1,$city2,$field)
- $result = $host.ui.PromptForChoice($title, $message, $options, 0)
- switch ($result) {
- 0 {
- set-ADUser $un -City "City1" -Company "Company Name" -PostalCode "55555" -State "ST" -StreetAddress "Blah street" -Title $Description -OfficePhone $Phone
- }
- 1 {
- set-ADUser $un -City "City2" -Company "Company Name" -PostalCode "55555" -State "ST" -StreetAddress "Blah Street2" -Title $Description -OfficePhone $Phone
- }
- 2 {
- "Field"
- }
- }
- set-aduser $un -Enabled $true
- $DomainControllers = Get-ADDomainController -Filter *
- ForEach ($DC in $DomainControllers.Name) {
- Write-Host "Processing for "$DC -ForegroundColor Green
- If ($Mode -eq "ExtraSuper") {
- REPADMIN /kcc $DC REPADMIN /syncall /A /e /q $DC
- }
- Else {
- REPADMIN /syncall $DC "dc=domain,dc=local" /d /e /q
- }
- }
- Invoke-Command -ComputerName machine.domain.local -ScriptBlock {import-module dirsync;Start-onlinecoexistencesync}
- Start-Sleep -s 360 connect-msolservice -credential $UserCredential
- Write-host "Setting Office 365 Account Password"
- Set-MsolUserPrincipalName -newuserprincipalname $un@domain.com -userprincipalname $un@domain.onmicrosoft.com
- Set-MsolUser -UserPrincipalName "$un@domain.com" -UsageLocation US Set-MsolUserLicense -UserPrincipalName "$un@domain.com" -AddLicenses domain:EXCHANGESTANDARD
- Set-MsolUser -UserPrincipalName "$un@domain.com" -StrongPasswordRequired $False start-sleep -s 90
- Set-MsolUserPassword -UserPrincipalName "$un@domain.com" -NewPassword $PlainPassword -ForceChangePassword $false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement