Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function New-O365User {
- $firstname = Read-Host -Prompt 'Enter the first name'
- $lastname = Read-Host -Prompt 'Enter the last name'
- $domain = Read-Host -Prompt 'Enter the domain'
- $displayname = -join("$firstname", " ", "$lastname")
- $userprincipalname = -join("$firstname", "$lastname", "@$domain")
- $usagelocation = Read-Host -Prompt 'Enter the usage location (GB/US/ETC.)'
- $var1 = (Get-MsolAccountSku).AccountSkuID
- $var2 = (Get-MsolAccountSku).ActiveUnits
- $var3 = (Get-MsolAccountSku).ConsumedUnits
- Write-Host $var1, $var2, $var3
- $license = Read-Host -Prompt 'Enter license type'
- $password = Read-Host -Prompt 'Choose a password'
- $answer = Read-Host -Prompt 'Do you wish the user to change password upon next login? (True/False)'
- IF($answer -eq "True"){[bool]$forcechangepassword = 1} `
- Else{[bool]$forcechangepassword = 0}
- $answer2 = Read-Host -Prompt 'Do you wish for this password to expire every 90 days? (True/False)'
- If($answer2 -eq "True"){[bool]$passwordexpiry = 1} `
- Else{[bool]$passwordexpiry = 0}
- New-MsolUser -FirstName $firstname `
- -LastName $lastname `
- -DisplayName $displayname `
- -UserPrincipalName $userprincipalname `
- -UsageLocation $usagelocation `
- -LicenseAssignment $license `
- -Password $password `
- -ForceChangePassword $forcechangepassword `
- -PasswordNeverExpires $passwordexpiry
- Write-Host –NoNewLine “A new user has been created: Username: $userprincipalname, Passowrd: $password” `
- -BackgroundColor “Green” -ForegroundColor “Black”
- Clear-UserVariables
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement