ShiftNick

Validate Office 365 Credentials

Sep 11th, 2015
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $problem = $true
  2. while ($problem = $true) {
  3.     try {
  4.         $O365Cred = Get-Credential -message "Please enter your Office365 Admin credentials"
  5.         $O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection -ea Stop
  6.        
  7.         Write-Output 'Logon Successful'
  8.         $problem = $false
  9.        
  10.         Import-PSSession $O365Session -AllowClobber
  11.         Connect-MsolService –Credential $O365Cred
  12.         }
  13.  
  14.     catch {
  15.         Write-Output 'Your username or password was incorrect, please try again'
  16.     }
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment