Search This Blog

Tuesday, March 8, 2016

Getting Started with Powershell and Office365 scripting

Here's what I know today...
# Managing Office 365 and Exchange Online with Windows PowerShell
# https://support.office.com/en-us/article/Managing-Office-365-and-Exchange-Online-with-Windows-PowerShell-06a743bb-ceb6-49a9-a61d-db4ffdf54fa6

#Connect to Office 365 PowerShell
$UserCredential = Get-Credential
$MsolService = Connect-MsolService -Credential $UserCredential
    # do stuff here like... 
    Get-Module
    Get-Command -Module MSOnline
# no remove: https://technet.microsoft.com/en-us/library/dn568015.aspx#Step8

# Connect to Exchange Online using remote PowerShell
Set-ExecutionPolicy RemoteSigned
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
    # do stuff here like... 
    Get-Module
    Get-Command -Module tmp_mjopwmqk.4nu #or whatever it is named

Remove-PSSession $Session

# Connect to Office 365 Compliance Center PowerShell - need a role first
Set-ExecutionPolicy RemoteSigned
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
    # do stuff here?
Remove-PSSession $Session #Security limits 3 connections only - Clean up!

# Connecting to Skype for Business Online by using Windows PowerShell 
$UserCredential = Get-Credential
$Session = New-CsOnlineSession -Credential $UserCredential
    # do stuff here
Remove-CsOnlineSession $Session

# Set up the SharePoint Online Management Shell Windows PowerShell environment 
$UserCredential = Get-Credential
$URL ='https://MyCompany-my.sharepoint.com'
Connect-SPOService -Url $URL -credential $UserCredential
    # do stuff here
Disconnect-SPOService

I wonder what I'll know tomorrow...