Skip to content

Commit 61160bf

Browse files
authored
Merge pull request #173355 from dagiro/1880158
1880158 - Automation CS - enable-managed-identity-for-automation.md
2 parents 4ba5c28 + eb51d43 commit 61160bf

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

articles/automation/enable-managed-identity-for-automation.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Using a system-assigned managed identity for an Azure Automation account
33
description: This article describes how to set up managed identity for Azure Automation accounts.
44
services: automation
55
ms.subservice: process-automation
6-
ms.date: 08/12/2021
6+
ms.date: 09/23/2021
77
ms.topic: conceptual
88
ms.custom: devx-track-azurepowershell
99
---
@@ -43,7 +43,7 @@ You can enable a system-assigned managed identity for an Azure Automation accoun
4343
$sub = Get-AzSubscription -ErrorAction SilentlyContinue
4444
if(-not($sub))
4545
{
46-
Connect-AzAccount -Identity
46+
Connect-AzAccount
4747
}
4848
4949
# If you have multiple subscriptions, set the one to use
@@ -265,11 +265,17 @@ New-AzRoleAssignment `
265265

266266
## Authenticate access with system-assigned managed identity
267267

268-
After you enable the managed identity for your Automation account and give an identity access to the target resource, you can specify that identity in runbooks against resources that support managed identity. For identity support, use the Az cmdlet `Connect-AzAccount` cmdlet. See [Connect-AzAccount](/powershell/module/az.accounts/Connect-AzAccount) in the PowerShell reference. Replace `SubscriptionID` with your actual subscription ID and then execute the following command:
268+
After you enable the managed identity for your Automation account and give an identity access to the target resource, you can specify that identity in runbooks against resources that support managed identity. For identity support, use the Az cmdlet `Connect-AzAccount` cmdlet. See [Connect-AzAccount](/powershell/module/az.accounts/Connect-AzAccount) in the PowerShell reference.
269269

270270
```powershell
271-
Connect-AzAccount -Identity
272-
$AzureContext = Set-AzContext -SubscriptionId "SubscriptionID"
271+
# Ensures you do not inherit an AzContext in your runbook
272+
Disable-AzContextAutosave -Scope Process
273+
274+
# Connect to Azure with system-assigned managed identity
275+
$AzureContext = (Connect-AzAccount -Identity).context
276+
277+
# set and store context
278+
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext
273279
```
274280

275281
> [!NOTE]

0 commit comments

Comments
 (0)