#Import-Module MSOnline
#$O365Cred = Get-Credential
#$O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection
#Import-PSSession $O365Session
#Connect-MsolService –Credential $O365Cred #Get-MsolUser
$users = Get-Content "FOLDERLOCATION"
foreach ($user in $users)
{#we are splitting the values from the users file here. There are #three entries so we split the value on a comma
#and split into three sections; first name, middle initial and last #name
$split = $user.Split(",", 2)
$first = $split[0];
$last = $split[1];
$display = $first + " " + $last
#get the first letter of the first name so we can create alias
$firstletter = $first.substring(0,1)
$alias = $firstletter + $last
$upn = $first + "." + $last + "@COMPANYNAME.onmicrosoft.com"
New-MsolUser -UserPrincipalName $upn -DisplayName $display -FirstName $first -LastName $last -UsageLocation "US" -LicenseAssignment "ENVIRONMENTNAME:ENTERPRISEPACK" -Password "Password!"
}
No comments:
Post a Comment