Skip to content

Commit 5c464a8

Browse files
Updated manage-runas-account.md
Get-AzSubscription cmdlet returns the subscription ID, name and tenant for subscriptions that the account can access. The $SubscriptionName variable would end up being null with the actual code (line 169): `$SubscriptionName = $subscription.Subscription.Name` Also change the current context to use the specified subscription. It may be better to explicitly define the context before create the Service Principal (as the default ​​for Role and Scope parameters are "Contributor" and the current subscription).
1 parent e32a89d commit 5c464a8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

articles/automation/manage-runas-account.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ if (!(($AzureRmProfileVersion.Major -ge 3 -and $AzureRmProfileVersion.Minor -ge
232232
233233
234234
Connect-AzAccount -Environment $EnvironmentName
235-
$Subscription = Get-AzSubscription -SubscriptionId $SubscriptionId
235+
$Subscription = Get-AzSubscription -SubscriptionId $SubscriptionId | Set-AzContext
236236
237237
# Create a Run As account by using a service principal
238238
$CertifcateAssetName = "AzureRunAsCertificate"
@@ -294,7 +294,7 @@ if ($CreateClassicRunAsAccount) {
294294
CreateAutomationCertificateAsset $ResourceGroup $AutomationAccountName $ClassicRunAsAccountCertifcateAssetName $PfxCertPathForClassicRunAsAccount $PfxCertPlainPasswordForClassicRunAsAccount $false
295295
296296
# Populate the ConnectionFieldValues
297-
$SubscriptionName = $subscription.Subscription.Name
297+
$SubscriptionName = $subscription.Name
298298
$ClassicRunAsAccountConnectionFieldValues = @{"SubscriptionName" = $SubscriptionName; "SubscriptionId" = $SubscriptionId; "CertificateAssetName" = $ClassicRunAsAccountCertifcateAssetName}
299299
300300
# Create an Automation connection asset named AzureRunAsConnection in the Automation account. This connection uses the service principal.

0 commit comments

Comments
 (0)