使用PowerShell获取Azure自动化帐户连接的服务主体。

huangapple go评论87阅读模式
英文:

Getting the service principal for an Azure Automation Account connection using PowerShell

问题

我知道如何使用Get-AutomationAccount在运行自动化帐户内的运行簿时检索连接详细信息。

但是,如果我想要能够报告在运行簿作业之外使用的AzureRunAsConnection的服务主体,该怎么办?

我尝试了类似以下的方法:

$automationAccount = Get-AzAutomationAccount -ResourceGroupName $rg -Name $name
$conn = $automationAccount | Get-AzAutomationConnection
$conn.FieldDefinitionValues

但是,FielDefinitionValues哈希表中什么都没有吗?我希望能看到租户ID、ApplicationId等信息。

我可以通过在门户上点击以下方式获取此信息:

AutomationAccount > Run as accounts > Azure RunAs Account

或者通过

AutomationAccount > Connections > AzureRunAsConnection

但是不知道如何通过PowerShell获取RunAs帐户的此信息?

提前感谢。

英文:

I know how Get-AutomationAccount can be used to retrieve the connection details internally while running a runbook within an automation account.

However, what if I want to be able to report on the service principal being used by the AzureRunAsConnection external to a runbook job?

I've tried something like the following:

$automationAccount = Get-AzAutomationAccount -ResourceGroupName $rg -Name $name
$conn = $automationAccount | Get-AzAutomationConnection
$conn.FieldDefinitionValues

However, the FielDefinitionValues hashtable has nothing in it? I was expecting to see things like tenantId, ApplicationId, etc.

I can get this information via the portal by clicking on:

> AutomationAccount > Run as accounts > Azure RunAs Account

or by

> AutomationAccount > Connections > AzureRunAsConnection

But can't see how I can get this info for the RunAs Account from PowerShell?

Thanks in advance.

答案1

得分: 1

是的,您需要使用$conn = $automationAccount | Get-AzAutomationConnection -Name "AzureRunAsConnection"

>可能是个bug?

这不是bug,因为这两个命令调用不同的REST API。

当使用$conn = $automationAccount | Get-AzAutomationConnection时,它调用了这个REST API Connection - List By Automation AccountfieldDefinitionValues的详细信息不会被公开,它将始终为null。您可以查看示例响应或使用Fiddler捕获PowerShell的请求。

使用PowerShell获取Azure自动化帐户连接的服务主体。

当使用$conn = $automationAccount | Get-AzAutomationConnection -Name "AzureRunAsConnection"时,它调用了这个REST API Connection - GetfieldDefinitionValues将包括您想要的属性。

使用PowerShell获取Azure自动化帐户连接的服务主体。

英文:

Yes, you need to use $conn = $automationAccount | Get-AzAutomationConnection -Name "AzureRunAsConnection" .

>Maybe a bug?

It is not a bug, because the two commands call different REST APIs.

When using $conn = $automationAccount | Get-AzAutomationConnection, it calls this rest api Connection - List By Automation Account, the details of fieldDefinitionValues will not be exposed, it will always be null. You could check the sample response or catch the request of the powershell with fiddler.

使用PowerShell获取Azure自动化帐户连接的服务主体。

When using $conn = $automationAccount | Get-AzAutomationConnection -Name "AzureRunAsConnection", it calls this rest api Connection - Get. The fieldDefinitionValues will include the properties you want.

使用PowerShell获取Azure自动化帐户连接的服务主体。

答案2

得分: 0

$conn = $automationAccount | Get-AzAutomationConnection -Name "AzureRunAsConnection"

英文:

You answered this yourself in the comments. But just to stop this question coming up as unanswered:

$conn = $automationAccount | Get-AzAutomationConnection -Name "AzureRunAsConnection" 

huangapple
  • 本文由 发表于 2020年1月3日 19:34:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577925.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定