排查共享资源问题Troubleshoot shared resource issues

本文讨论了在使用 Azure 自动化中的共享资源时可能会出现的问题。This article discusses issues that might arise when you're using shared resources in Azure Automation.

模块Modules

场景:在导入期间模块处于停滞状态Scenario: A module is stuck during import

问题Issue

导入或更新 Azure 自动化模块时,模块停滞在“正在导入”状态。A module is stuck in the Importing state when you're importing or updating your Azure Automation modules.

原因Cause

由于导入 PowerShell 模块是一个复杂的多步骤过程,模块可能不会正确导入,并且停滞在某种暂时性状态。Because importing PowerShell modules is a complex, multistep process, a module might not import correctly, and can be stuck in a transient state. 若要详细了解导入过程,请参阅导入 PowerShell 模块To learn more about the import process, see Importing a PowerShell module.

解决方法Resolution

若要解决此问题,必须使用 Remove-AzAutomationModule cmdlet 删除处于停滞状态的模块。To resolve this issue, you must remove the module that is stuck by using the Remove-AzAutomationModule cmdlet. 然后,可以重试导入模块。You can then retry importing the module.

Remove-AzAutomationModule -Name ModuleName -ResourceGroupName ExampleResourceGroup -AutomationAccountName ExampleAutomationAccount -Force

场景:尝试更新后,AzureRM 模块在导入期间停滞Scenario: AzureRM modules are stuck during import after an update attempt

问题Issue

尝试更新 AzureRM 模块后,帐户中一直显示包含以下消息的横幅:A banner with the following message stays in your account after trying to update your AzureRM modules:

Azure modules are being updated

原因Cause

更新自动化帐户中的 AzureRM 模块时存在一个已知问题。There is a known issue with updating the AzureRM modules in an Automation account. 具体而言,如果模块所在的资源组具有以 0 开头的数字名称,则会出现此问题。Specifically, the problem occurs if the modules are in a resource group with a numeric name starting with 0.

解决方法Resolution

若要更新自动化帐户中的 AzureRM 模块,该帐户必须位于采用字母数字名称的资源组中。To update your AzureRM modules in your Automation account, the account must be in a resource group with an alphanumeric name. 采用以 0 开头的数字名称的资源组目前无法更新 AzureRM 模块。Resource groups with numeric names starting with 0 are unable to update AzureRM modules at this time.

场景:模块无法导入,或者 cmdlet 在导入后无法执行Scenario: Module fails to import or cmdlets can't be executed after importing

问题Issue

模块无法导入,或者虽然导入成功,但无法提取 cmdlet。A module fails to import, or it imports successfully, but no cmdlets are extracted.

原因Cause

模块无法成功导入到 Azure 自动化中的一些常见原因是:Some common reasons that a module might not successfully import to Azure Automation are:

  • 结构与自动化所需的结构不匹配。The structure doesn't match the structure that Automation needs.
  • 该模块依赖于其他模块,而后者尚未部署到自动化帐户。The module depends on another module that hasn't been deployed to your Automation account.
  • 该模块的文件夹中缺少依赖项。The module is missing its dependencies in the folder.
  • 使用了 New-AzAutomationModule cmdlet 来上传该模块,但你未提供完整的存储路径,或者未使用可公开访问的 URL 来加载该模块。The New-AzAutomationModule cmdlet is being used to upload the module, and you haven't provided the full storage path or haven't loaded the module by using a publicly accessible URL.

解决方法Resolution

使用以下任一解决方法来解决此问题:Use any of these solutions to fix the issue:

  • 确保该模块遵循以下格式:ModuleName.zip -> 模块名称或版本号 -> (ModuleName.psm1, ModuleName.psd1)。Make sure that the module follows the format: ModuleName.zip -> ModuleName or Version Number -> (ModuleName.psm1, ModuleName.psd1).
  • 打开 .psd1 文件,查看该模块是否有任何依赖项。Open the .psd1 file and see if the module has any dependencies. 如果有,则将这些模块上传到自动化帐户。If it does, upload these modules to the Automation account.
  • 确保所引用的任何 .dll 文件都存在于模块文件夹中。Make sure that any referenced .dll files are present in the module folder.

场景:Update-AzureModule.ps1 在更新模块时暂停Scenario: Update-AzureModule.ps1 suspends when updating modules

问题Issue

使用 Update-AzureModule.ps1 Runbook 更新 Azure 模块时,模块更新过程暂停。When you're using the Update-AzureModule.ps1 runbook to update your Azure modules, the module update process is suspended.

原因Cause

对于此 Runbook,用于确定可同时更新的模块数的默认设置为 10。For this runbook, the default setting to determine how many modules are updated simultaneously is 10. 如果同时更新太多模块,则更新过程容易出错。The update process is prone to errors when too many modules are being updated at the same time.

解决方法Resolution

在同一个自动化帐户中需要使用所有 AzureRM 或 Az 模块的情况并不常见。It's not common that all the AzureRM or Az modules are required in the same Automation account. 你应当只导入所需的特定模块。You should only import the specific modules that you need.

备注

避免导入整个 Az.AutomationAzureRM.Automation 模块,否则会导入包含的所有模块。Avoid importing the entire Az.Automation or AzureRM.Automation module, which imports all contained modules.

如果更新过程暂停,请向 Update-AzureModules.ps1 脚本添加 SimultaneousModuleImportJobCount 参数,并提供小于默认值 10 的值。If the update process suspends, add the SimultaneousModuleImportJobCount parameter to the Update-AzureModules.ps1 script, and provide a lower value than the default of 10. 如果实现此逻辑,请尝试从值 3 或 5 开始。If you implement this logic, try starting with a value of 3 or 5. SimultaneousModuleImportJobCount 是用于更新 Azure 模块的 Update-AutomationAzureModulesForAccount 系统 Runbook 的一个参数。SimultaneousModuleImportJobCount is a parameter of the Update-AutomationAzureModulesForAccount system runbook that is used to update Azure modules. 如果进行此调整,更新过程的运行时间会变长,但会提高成功完成的可能性。If you make this adjustment, the update process runs longer, but has a better chance of completing. 以下示例显示了该参数及其在 runbook 中的放置位置:The following example shows the parameter and where to put it in the runbook:

        $Body = @"
           {
              "properties":{
              "runbook":{
                  "name":"Update-AutomationAzureModulesForAccount"
              },
              "parameters":{
                   ...
                   "SimultaneousModuleImportJobCount":"3",
                   ... 
              }
             }
          }
"@

运行方式帐户Run As accounts

场景:无法创建或更新运行方式帐户Scenario: You're unable to create or update a Run As account

问题Issue

尝试创建或更新运行方式帐户时,收到类似于以下内容的错误:When you try to create or update a Run As account, you receive an error similar to the following:

You do not have permissions to create…

原因Cause

你没有创建或更新运行方式帐户所需的权限,或者资源在资源组级别被锁定。You don't have the permissions that you need to create or update the Run As account, or the resource is locked at a resource group level.

解决方法Resolution

若要创建或更新运行方式帐户,你必须对运行方式帐户使用的各种资源具有适当的权限To create or update a Run As account, you must have appropriate permissions to the various resources used by the Run As account.

如果问题是由某个锁造成的,请验证是否可以删除该锁。If the problem is because of a lock, verify that the lock can be removed. 在 Azure 门户中转到被锁定的资源,右键单击该锁,然后选择“删除”。Then go to the resource that is locked in Azure portal, right-click the lock, and select Delete.

场景:执行 Runbook 时收到错误“在 DLL 'iplpapi.dll' 中找不到名为 'GetPerAdapterInfo' 的入口点”Scenario: You receive the error "Unable to find an entry point named 'GetPerAdapterInfo' in DLL 'iplpapi.dll'" when executing a runbook

问题Issue

执行 Runbook 时收到以下异常:When you're executing a runbook, you receive the following exception:

Unable to find an entry point named 'GetPerAdapterInfo' in DLL 'iplpapi.dll'

原因Cause

此错误很可能是由于错误配置了运行方式帐户而造成的。This error is most likely caused by an incorrectly configured Run As account.

解决方法Resolution

确保正确配置运行方式帐户。Make sure that your Run As account is properly configured. 然后,验证在 Runbook 中是否提供了用于在 Azure 中进行身份验证的正确代码。Then verify that you have the proper code in your runbook to authenticate with Azure. 以下示例展示了 Runbook 中使用运行方式帐户向 Azure 进行身份验证的代码片段。The following example shows a snippet of code to authenticate to Azure in a runbook by using a Run As account.

$connection = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzAccount -ServicePrincipal -Tenant $connection.TenantID `
-ApplicationID $connection.ApplicationID -CertificateThumbprint $connection.CertificateThumbprint -Environment AzureChinaCloud

后续步骤Next steps

如果本文未解决你的问题,请尝试通过以下渠道之一获取更多支持:If this article doesn't resolve your issue, try one of the following channels for additional support: