Skip to content

Commit e7cafba

Browse files
authored
Merge pull request #266760 from TimShererWithAquent/graphps39
Bulk update | 174285 MS Graph PowerShell cmdlet update Phase 3
2 parents 14d276b + d0558f2 commit e7cafba

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

articles/automation/manage-office-365.md

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: This article tells how to use Azure Automation to manage Office 365
44
services: automation
55
ms.date: 11/05/2020
66
ms.topic: conceptual
7-
ms.custom: has-azure-ad-ps-ref
7+
ms.custom: has-azure-ad-ps-ref, azure-ad-ref-level-one-done
88
---
99

1010
# Manage Office 365 services
@@ -20,28 +20,21 @@ You need the following to manage Office 365 subscription services in Azure Autom
2020
* Microsoft Entra ID. See [Use Microsoft Entra ID in Azure Automation to authenticate to Azure](automation-use-azure-ad.md).
2121
* An Office 365 tenant, with an account. See [Set up your Office 365 tenant](/sharepoint/dev/spfx/set-up-your-developer-tenant).
2222

23-
## Install the MSOnline and MSOnlineExt modules
23+
## Install Microsoft Graph PowerShell
2424

25-
Use of Office 365 within Azure Automation requires Microsoft Entra ID for Windows PowerShell (`MSOnline` module). You'll also need the module [`MSOnlineExt`](https://www.powershellgallery.com/packages/MSOnlineExt/1.0.35), which simplifies Microsoft Entra management in single- and multi-tenant environments. Install the modules as described in [Use Microsoft Entra ID in Azure Automation to authenticate to Azure](automation-use-azure-ad.md).
25+
Use of Office 365 within Azure Automation requires the Microsoft Graph PowerShell module.
26+
27+
```powershell
28+
Install-Module Microsoft.Graph -Scope CurrentUser
29+
```
2630

2731
>[!NOTE]
28-
>To use MSOnline PowerShell, you must be a member of Microsoft Entra ID. Guest users can't use the module.
32+
>To use Microsoft Graph PowerShell, you must be a member of Microsoft Entra ID. Guest users can't use the module.
2933
3034
## Create an Azure Automation account
3135

3236
To complete the steps in this article, you need an account in Azure Automation. See [Create an Azure Automation account](./quickstarts/create-azure-automation-account-portal.md).
3337

34-
## Add MSOnline and MSOnlineExt as assets
35-
36-
Now add the installed MSOnline and MSOnlineExt modules to enable Office 365 functionality. Refer to [Manage modules in Azure Automation](shared-resources/modules.md).
37-
38-
1. In the Azure portal, select **Automation Accounts**.
39-
2. Choose your Automation account.
40-
3. Select **Modules Gallery** under **Shared Resources**.
41-
4. Search for MSOnline.
42-
5. Select the `MSOnline` PowerShell module and click **Import** to import the module as an asset.
43-
6. Repeat steps 4 and 5 to locate and import the `MSOnlineExt` module.
44-
4538
## Create a credential asset (optional)
4639

4740
It's optional to create a credential asset for the Office 365 administrative user who has permissions to run your script. It can help, though, to keep from exposing user names and passwords inside PowerShell scripts. For instructions, see [Create a credential asset](automation-use-azure-ad.md#create-a-credential-asset).
@@ -55,36 +48,32 @@ To run Office 365 subscription services, you need an Office 365 service account
5548
## Connect to the Microsoft Entra online service
5649

5750
>[!NOTE]
58-
>To use the MSOnline module cmdlets, you must run them from Windows PowerShell. PowerShell Core does not support these cmdlets.
51+
>To use the Microsoft Graph PowerShell module cmdlets, you must run them from Windows PowerShell. PowerShell Core does not support these cmdlets.
5952
60-
You can use the MSOnline module to connect to Microsoft Entra ID from the Office 365 subscription. The connection uses an Office 365 user name and password or uses multi-factor authentication (MFA). You can connect using the Azure portal or a Windows PowerShell command prompt (does not have to be elevated).
53+
You can connect to Microsoft Entra ID from the Office 365 subscription. The connection uses an Office 365 user name and password or uses multi-factor authentication (MFA). You can connect using the Azure portal or a Windows PowerShell command prompt (does not have to be elevated).
6154

62-
A PowerShell example is shown below. The [Get-Credential](/powershell/module/microsoft.powershell.security/get-credential) cmdlet prompts for credentials and stores them in the `Msolcred` variable. Then the [Connect-MsolService](/powershell/module/msonline/connect-msolservice) cmdlet uses the credentials to connect to the Azure directory online service. If you want to connect to a specific Azure environment, use the `AzureEnvironment` parameter.
55+
A PowerShell example is shown below. For more information, see [Connect-MgGraph](/powershell/module/microsoft.graph.authentication/connect-mggraph).
6356

6457
```powershell
65-
$Msolcred = Get-Credential
66-
Connect-MsolService -Credential $MsolCred -AzureEnvironment "AzureCloud"
58+
Connect-MgGraph -Scopes "Directory.Read.All"
6759
```
6860

69-
If you don't receive any errors, you've connected successfully. A quick test is to run an Office 365 cmdlet, for example, `Get-MsolUser`, and see the results. If you receive errors, note that a common problem is an incorrect password.
70-
71-
>[!NOTE]
72-
>You can also use the AzureRM module or the Az module to connect to Microsoft Entra ID from the Office 365 subscription. The main connection cmdlet is [Connect-AzureAD](/powershell/module/azuread/connect-azuread). This cmdlet supports the `AzureEnvironmentName` parameter for specific Office 365 environments.
61+
If you don't receive any errors, you've connected successfully. A quick test is to run an Office 365 cmdlet, for example, [Get-MgUser](/powershell/module/microsoft.graph.users/get-mguser), and see the results.
7362

7463
## Create a PowerShell runbook from an existing script
7564

76-
You access Office 365 functionality from a PowerShell script. Here's an example of a script for a credential named `Office-Credentials` with user name of `[email protected]`. It uses `Get-AutomationPSCredential` to import the Office 365 credential.
65+
You access Office 365 functionality from a PowerShell script.
7766

7867
```powershell
7968
$emailFromAddress = "[email protected]"
8069
$emailToAddress = "[email protected]"
8170
$emailSMTPServer = "outlook.office365.com"
8271
$emailSubject = "Office 365 License Report"
83-
8472
$credObject = Get-AutomationPSCredential -Name "Office-Credentials"
85-
Connect-MsolService -Credential $credObject
8673
87-
$O365Licenses = Get-MsolAccountSku | Out-String
74+
Connect-MgGraph -Scopes "Directory.Read.All"
75+
76+
$O365Licenses = Get-MgSubscribedSku | Out-String
8877
Send-MailMessage -Credential $credObject -From $emailFromAddress -To $emailToAddress -Subject $emailSubject -Body $O365Licenses -SmtpServer $emailSMTPServer -UseSSL
8978
```
9079

0 commit comments

Comments
 (0)