Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function New-O365User {
  2.  
  3.          $firstname = Read-Host -Prompt 'Enter the first name'
  4.          $lastname = Read-Host -Prompt 'Enter the last name'
  5.          $domain = Read-Host -Prompt 'Enter the domain'
  6.          $displayname = -join("$firstname", " ", "$lastname")
  7.          $userprincipalname = -join("$firstname", "$lastname", "@$domain")
  8.          $usagelocation = Read-Host -Prompt 'Enter the usage location (GB/US/ETC.)'
  9.  
  10.             $var1 = (Get-MsolAccountSku).AccountSkuID
  11.             $var2 = (Get-MsolAccountSku).ActiveUnits
  12.             $var3 = (Get-MsolAccountSku).ConsumedUnits
  13.  
  14.                     Write-Host $var1, $var2, $var3
  15.  
  16.          $license = Read-Host -Prompt 'Enter license type'
  17.  
  18.          $password = Read-Host -Prompt 'Choose a password'
  19.  
  20.          $answer = Read-Host -Prompt 'Do you wish the user to change password upon next login? (True/False)'
  21.                 IF($answer -eq "True"){[bool]$forcechangepassword = 1}  `
  22.                 Else{[bool]$forcechangepassword = 0}
  23.  
  24.          $answer2 = Read-Host -Prompt 'Do you wish for this password to expire every 90 days? (True/False)'
  25.                 If($answer2  -eq "True"){[bool]$passwordexpiry = 1}  `
  26.                 Else{[bool]$passwordexpiry = 0}
  27.  
  28.  
  29.           New-MsolUser -FirstName $firstname  `
  30.                        -LastName $lastname  `
  31.                        -DisplayName $displayname  `
  32.                        -UserPrincipalName $userprincipalname  `
  33.                        -UsageLocation $usagelocation  `
  34.                        -LicenseAssignment $license  `
  35.                        -Password $password  `
  36.                        -ForceChangePassword $forcechangepassword  `
  37.                        -PasswordNeverExpires $passwordexpiry
  38.  
  39.           Write-Host –NoNewLine  “A new user has been created: Username: $userprincipalname, Passowrd: $password”  `
  40.           -BackgroundColor “Green” -ForegroundColor “Black”
  41.  
  42.           Clear-UserVariables                          
  43.      
  44.          }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement