Connect to Office365
Connecting to Office365 consists of three different, separate connections. One is to make the connection with Exchange Online, this is to be able to carry out Exchange related tasks. The second it to import the MSONLINE module, that is roughly the ActiveDirectory equivalent of the cloud. That gives you the commandlets to administer user account, licenses, etc in O365. The third one adds the compliance commandlets to the session, they are rare to use, mainly when legal hold is needed or searching then entire tenant for certain emails is needed. Also, you can concatenate the commands, asking for the credentials once, or you can save the credentials in an encrypted file that you can import each time you want to authenticate. That way the manual input of credentials is not needed at all.
Connect to Exchange Online (EOL)
$admin = 'admin@opentechtips.com.onmicrosoft.com' $cred = Get-Credential -Username $admin -Message "Hi" $exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange ` -ConnectionUri https://outlook.office365.com/powershell-liveid/ ` -Credential $cred -Authentication "Basic" -AllowRedirection Import-PSSession $exchangeSession -DisableNameChecking
Connect to MSONLINE (cloud AD)
$admin = 'admin@opentechtips.com.onmicrosoft.com' $cred = Get-Credential -Username $admin -Message "Hi" Import-Module MsOnline Connect-MsolService -Credential $cred
Import the Compliance cmdlets
$admin = 'admin@opentechtips.com.onmicrosoft.com' $cred = Get-Credential -Username $admin -Message "Hi" $compliances = New-PSSession -ConfigurationName Microsoft.Exchange ` -ConnectionUri "https://ps.compliance.protection.outlook.com/powershell-liveid/" ` -Credential $cred -Authentication "Basic" -AllowRedirection Import-PSSession $compliances -DisableNameChecking
Connect to On-Prem servers
This step is much simpler as we assume you already are logged in as the admin user who has the necessary rights for Exchange administration. If you want to authenticate as another user, just use the same “-Credential $cred” switch as we did earlier. It can be omitted though.
$exchSession = New-PSSession -ConfigurationName Microsoft.Exchange ` -ConnectionUri "http://mail.alwayshotcafe.com/powershell/" ` -Authentication kerberos Import-PSSession $exchPremSession
Comments