Advertisement
Guest User

Untitled

a guest
May 16th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #This function is to connect with Office 365 simply by using "connect-o365" within a powershell window.
  2.  
  3. function connect-o365 {
  4.  
  5.  
  6. #This uses a password file converted to secure string that should already be in place. To create one yourself use the below commented command
  7. #Read-Host “Type your Office 365 Exchange Online password: ” –AsSecureString | ConvertFrom-SecureString | Set-Content C:\Scripts\o365.txt
  8. $SecureData = cat C:\Scripts\o365.txt | convertto-securestring
  9.  
  10. #change the email in the below line to your email
  11. $LiveCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "apenick@horizonind.com",$SecureData
  12.  
  13. Import-Module MSOnline
  14.  
  15. $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
  16. Import-PSSession $Session
  17.  
  18.  
  19. Start-Sleep -Seconds 5
  20. Connect-MsolService -Credential $LiveCred
  21.  
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement