简单地说,我在 Azure 中使用 runbook
自动化运行 Connect-AzureRmAccount
,它给出了以下错误:
Unable to find an entry point named 'GetPerAdapterInfo' in DLL 'iphlpapi.dll'.
我已经导入了 Azureprofile 模块,但我无法弄清楚问题是什么。
最佳答案
如果你想在 Runbook 中使用 PowerShell 命令 Connect-AzureRmAccount
连接到 Azure 帐户,那么确实没有必要。正如我在评论中所说,当您使用 Runbook 时,您已经拥有帐户的租户的精确订阅。因此,只需运行脚本而不连接帐户即可。
如果您确实想使用 PowerShell 连接,可以像这样使用服务主体:
Disable-AzureRmContextAutosave –Scope Process
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzureRmAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationID $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
但我真的建议您直接运行 Runbook 中的 PowerShell 脚本。
更新
创建 Runbook 时,将有一个连接供您运行 PowerShell 脚本。或者您可以根据需要创建连接。请参阅Connection assets in Azure Automation 。您可以只使用默认连接,使用如下代码:
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
关于azure - 连接-AzureRmAccount : Unable to find an entry point named 'GetPerAdapterInfo' in DLL 'iphlpapi.dll' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54272880/