Connect-AzureRmAccount:在DLL“ iphlpapi.dll”中找不到名为“ GetPerAdapterInfo”的入口点

时间:2019-01-20 01:45:06

标签: azure powershell automation cloud

简而言之,我正在Azure中使用Connect-AzureRmAccount自动化来运行runbook,但出现以下错误:

  

在DLL中找不到名为“ GetPerAdapterInfo”的入口点   “ iphlpapi.dll”。

我已经导入了Azureprofile模块,但我不知道是什么问题。

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,就我而言,我只是尝试使用Azure Cmdlet Get-AzVm。

我以前使用的代码与上面的Charles所写的类似,问题是,由于您不能同时使用AzureRM和新的Azure模块,因此该问题不适用于Az Cmdlet。

我将所有内容替换为以下内容,现在可以使用了:

Disable-AzContextAutosave –Scope Process
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzAccount -ServicePrincipal -Tenant $Conn.TenantID `
-ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
$AzureContext = Select-AzSubscription -SubscriptionId $Conn.SubscriptionID

我在以下文章中发现了这一点:https://docs.microsoft.com/en-us/azure/automation/automation-first-runbook-textual

答案 1 :(得分:0)

如果要使用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
    }
}