Monday, July 20, 2015

3 PowerShell Profiles - Connect to O365

PowerShell Profiles - Connect to O365

Check for profiles
PS C:\> Test-Path $profile
Create a profile
New-Item $profile -ItemType File -Force
edit the profile script using PowerShell ISE to make a customized function:
powershell_ise.exe $profile
http://exchangeserverpro.com/create-powershell-profile/

Customized function:
Function Connect-EXOnline {

    $URL = "https://ps.outlook.com/powershell"
    
    $Credentials = Get-Credential -Message "Enter your Office 365 admin credentials"

    $EXOSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $URL -Credential $Credentials -Authentication Basic -AllowRedirection -Name "Exchange Online"

    Import-PSSession $EXOSession

}

Function Disconnect-EXOnline {
    
    Remove-PSSession -Name "Exchange Online"

}

Open a new session  and run the functions
Connect-EXOnline
Log in with your Office 365 admin credentials.

Sample function:
Check for mailboxes
Get-Mailbox

Be sure and disconnect
Disconnect-EXOnline

http://exchangeserverpro.com/powershell-function-connect-office-365/




No comments:

Post a Comment