I am running Azure Automation Runbook which has PowerShell script to restart the Azure Web App at defined scheduled. While test running the below script I am getting error:
$connectionName = "AzureRunAsConnection"
$servicePrincipalConnection = Get-AutomationConnection -Name $connectionName
$null = Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
$null = Select-AzureRmSubscription -SubscriptionId 'SubscriptionID'
Restart-AzureRmWebApp -ResourceGroupName 'RGroupName' -Name 'webappname'
Error details:
Add-AzureRmAccount : Unable to find an entry point named 'GetPerAdapterInfo' in DLL 'iphlpapi.dll'.
Is this error related to having not enough access?
Thank you!
I can reproduce the issue with your script on my side.
To fix the issue, change your script into the one below, it will work fine.
Note: Navigate to your automation account -> Modules
-> make sure the modules AzureRM.Profile
, AzureRM.Websites
are existing, if not, click Browse Gallery
to search them and import.
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
$null = 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
}
}
$null = Select-AzureRmContext -Subscription 'SubscriptionID'
Restart-AzureRmWebApp -ResourceGroupName 'RGroupName' -Name 'webappname'