Good afternoon
I guess that this is relation is true:
Azure Tenant
» Azure Subscription
» Azure Automation
» Runbook
Therefore I have this question:
Is there a PowerShell command which can be used to get the TenantID in which the Runbook is running?
If you want to run the command inside of the runbook, you could use this:
$servicePrincipalConnection = Get-AutomationConnection -Name "AzureRunAsConnection"
Write-Output $servicePrincipalConnection.TenantId
Note: there is a prerequisite, when you create the automation account, you need to select Create Azure Run As account
with Yes
, otherwise the AzureRunAsConnection
is not existing.