Office 365

Office 365 (O365) constitutes a number of subscription services as part of the Microsoft Office product line. It is one of the most well-known examples of Software as a Service, which provides software licensed on a subscription base. It will be updated continuously and doesn't need to be stored in the private cloud. There are different consumer and enterprise plans available.

As we are focusing on enterprise environments, we will only visualize those:

https://products.office.com/en/business/compare-more-office-365-for-business-plans:

To establish the connection, there are two methods available.

The first one is to connect with the Microsoft Azure Active Directory Module for Windows PowerShell as follows:

  1. You will need to install the 64-bit version of the Microsoft Online Services Sign-in Assistant, which can be found at the following link:

https://www.microsoft.com/de-de/download/details.aspx?id=41950

  1. Next, the MSOnline module is installed and the authentication is processed with username and password:
#Installing the Microsoft Azure Active Directory Module 
Install-Module MSOnline -Force

#Credentials to connect to online service
$UserCredential = Get-Credential -UserName '[email protected]'

#Showing credentials
$UserCredential

#Connect to service
Connect-MsolService -Credential $UserCredential

#proving if the connection has been established correctly
try {
$connectionSuccessfullyEstablished = Get-MsolUser.Count -ge 0
}
catch {
$connectionSuccessfullyEstablished = $false
}

We have also proved that the connections have been established correctly by executing Get-MsolUser and validating its return values. To use multifactor authentication for this task, you can just leave the credentials empty:

#multifactor authentication 
Connect-MsolService

However, this connection method is no longer recommended, and the cmdlets have been updated:

The new module is AzureAD and the code reference can be found at the following link:

https://docs.microsoft.com/de-de/powershell/module/Azuread/?view=azureadps-2.0

The connection with the newer Azure Active Directory PowerShell for Graph module works in a similar way:

#Installing the Microsoft Azure Active Directory Module 
Install-Module -Name AzureAD -Force

#Credentials to connect to online service
$UserCredential = Get-Credential -UserName '[email protected]' -Message 'Password'

#Showing credentials
$UserCredential

#Connect to service
#proving if the connection has been established correctly
try {
Connect-AzureAD -Credential $UserCredential
$connectionSuccessfullyEstablished = $true
}
catch {
$connectionSuccessfullyEstablished = $false
}

The approach using multifactor authentication also behaves the same:

#multifactor authentication 
Connect-AzureAD

We recommend always disconnecting from services if the automation scripts don't necessarily need the connections any more. When you are managing more tenants, this will become a mandatory step:

#Disconnect - if more tenants are being managed
Disconnect-AzureAD

To work and find the available cmdlets, you can use the methods described in the very first chapters of this book:

#Showing all cmdlets
Get-Command -Module AzureAD

#Retrieving all user information
Get-AzureADUser | Select-Object *

#Showing examples for dedicated cmdlets
Get-Help New-AzureADUser -Examples

Most of the cmdlets are self-explanatory and, in combination with the provided help and examples, you will accomplish most of the tasks without any additional help. The following line shows the creation of a new user:

#Creating new user
New-AzureADUser -DisplayName "David" -UserPrincipalName "[email protected]" -AccountEnabled $true -MailNickName "Dave" -PasswordProfile $passwortProfile

One great option for providing many arguments to the cmdlets can be achieved with splatting:

#Creating new user using splatting
$HashArguments = @{
DisplayName = "test.txt"
UserPrincipalName = "test2.txt"
AccountEnabled = $true
MailNickName = "Dave"
PasswordProfile = $passwortProfile
}
New-AzureADUser @HashArguments

Also, take a dedicated look at Chapter 6, Working with Data, if you want to create bulk inserts into O365 by using external data providers.

Some further examples for working with users follow:

#Grouping user to region and Country
Get-AzureADUser | Group-Object Region
Get-AzureADUser | Group-Object Country

#Retrieving all users grouped to Region
Get-AzureADUser | Group-Object Region | Sort-Object Count -Descending

#Retrieve UPNs
Get-AzureADUser | Sort-Object UserPrincipalName | Select-Object UserPrincipalName

#Change user properties
Set-AzureADUser -ObjectID "[email protected]" -UsageLocation "DE"

#Setting properties for specific user groups
Get-AzureADUser | Where-Object {$_.Department -eq "Development"} | Set-AzureADUser -UsageLocation "US"
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.143.4