Office 365 Powershell Connections

Office 365 Powershell Connections

Many businesses have already transitioned to Office 365, and those that haven't most likely will be in the near future. System Administrator will be a

Office 365 – Offboarding users with Powershell
Office 365 – Implementing a Display Name Format for all users
Disable Giphy in Microsoft Teams

Many businesses have already transitioned to Office 365, and those that haven’t most likely will be in the near future. System Administrator will be adding another skill set to their resumes’, that is managing Office 365. Wikipedia defines Office 365 as, a line of subscription services offered by Microsoft, as part of the Microsoft Office product line. The brand encompasses plans that allow use of the Microsoft Office software suite over the life of the subscription, as well as cloud-based software as a service products for business environments, such as hosted Exchange Server, Skype for Business Server, and SharePoint among others. All Office 365 plans include automatic updates to their respective software at no additional charge, as opposed to conventional licenses for these programs—where new versions require purchase of a new license.

Connecting to Azure Active Directory:

First you will need Azure Active Directory PowerShell for Graph (http://www.powershellgallery.com/packages/AzureAD/2.0.1.3)
Run “Install-Module -Name AzureAD”

Role Requirement
You will need Global Administrative role in Azure AD in order to manage objects.

You would normally connect to AzureAD with the following commands:

$cred = Get-Credential
Connect-AzureAD -Credential $cred

But what if you have MFA (Multi-factor Auth) enabled? You cannot use the -Credential because you cannot automatically save the credentials when you are using MFA, you simply use the Connect-AzureAD command and you will be prompted for user/password, then you will be prompted for the second authentication method.

You can check that you are connected by issuing a command such as “Get-AzureADUser” which will list the user accounts.

To disconnect you simply use: Disconnect-AzureAD

Connecting to Exchange Online:

# Use you Office 365 administrative credentials
$usercredential = Get-Credential
$Session = New-Pssession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-Pssession $session

You should at this point be connected to your Office 365 account. You can test this by running:

Get-Mailbox

This should list all of your user’s mailboxes.

Connecting to SharePoint Online:

You will need the SharePoint Online Management Shell module (https://www.microsoft.com/en-us/download/details.aspx?id=35588) You will also need to be a SharePoint Online Administrator and know the URL of the SharePoint Online Admin Center (https://<org name>-admin.sharepoint.com).

#Get Credential
$cred = get-credential
# Establish Conneciton
Connect SPOService -Url https://<SP Admin Center>.sharepoint.com -credential $cred

If you are using MFA, simply do not use Credentials commands:

Connect SPOService -Url https://<SP Admin Center>.sharepoint.com

Test your connection using the “Get-SPOSite” command to list all your site collections.

Disconnect using “Disconnect-SPOService”

Connecting to Office 365 Security and Compliance Center:

This is very similar to the other connections.

#Get Credentials
$cred = get-credential
#Establish connection
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection

Connecting to Skype for Business Online:

First you will need the Skype for Business Online module (https://www.microsoft.com/en-us/download/details.aspx?id=39366)

#Get Credentials
$cred = Get-Credential
#Establish connection
$Session = New-CsOnlineSession -Credential $cred
#Add into current session
Import-PSSession $Session

Connecting to Microsoft Teams:

First you will need the Microsoft Teams module which is hosted in the PowerShell Gallery (https://www.powershellgallery.com/packages/MicrosoftTeams/0.9.1)

#Get Credentials
$cred = Get-Credential
#Establish connection
Connect-MicrosoftTeams -Credential $cred

COMMENTS

WORDPRESS: 0