[英]Azure Automation Hybrid-Worker Get-AutomationPSCredential for PowerShell 7
We are moving a few Azure Automation Hybrid-worker scripts to PowerShell 7.1.我们正在将一些 Azure 自动化混合工作器脚本移至 PowerShell 7.1。 In doing so one of the commands that work in PowerShell 5.1 is: [PSCredential] $AutomationCredential = Get-AutomationPSCredential -Name 'abcdef'
.为此,在 PowerShell 5.1 中工作的命令之一是: [PSCredential] $AutomationCredential = Get-AutomationPSCredential -Name 'abcdef'
。 When we try the same command in PowerShell 7.1 we get an error The 'Get-AutomationPSCredential' command was found in the module 'Orchestrator.AssetManagement.Cmdlets', but the module could not be loaded. For more information, run 'Import-Module Orchestrator.AssetManagement.Cmdlets'
当我们在 PowerShell 7.1 中尝试相同的命令时,我们收到错误The 'Get-AutomationPSCredential' command was found in the module 'Orchestrator.AssetManagement.Cmdlets', but the module could not be loaded. For more information, run 'Import-Module Orchestrator.AssetManagement.Cmdlets'
The 'Get-AutomationPSCredential' command was found in the module 'Orchestrator.AssetManagement.Cmdlets', but the module could not be loaded. For more information, run 'Import-Module Orchestrator.AssetManagement.Cmdlets'
We have added the Import-Module to the code but we get Could not load file or assembly 'JobRuntimeData.Client, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified
我们已将导入模块添加到代码中,但我们得到Could not load file or assembly 'JobRuntimeData.Client, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified
Could not load file or assembly 'JobRuntimeData.Client, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified
. Could not load file or assembly 'JobRuntimeData.Client, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified
。
We do find Orchestrator.AssetManagement.Cmdlets the on the hybrid-worker, in the sandbox area.我们确实在沙盒区域中的混合工作器上找到 Orchestrator.AssetManagement.Cmdlets。 We know that this module is loaded when the hybrid-worker is installed ( https://docs.microsoft.com/en-us/azure/automation/shared-resources/modules#internal-cmdlets ).我们知道这个模块是在安装 hybrid-worker 时加载的 ( https://docs.microsoft.com/en-us/azure/automation/shared-resources/modules#internal-cmdlets )。
Based on the Microsoft official document基于微软官方文档
The 'Get-AutomationPSCredential
is currently supported till Azure powershell 6.6.0
'Get-AutomationPSCredential
目前支持直到Azure powershell 6.6.0
NOTE : Powershell 7.1 is still in preview so this may be the reason for the error .注意:Powershell 7.1 仍处于预览阶段,所以这可能是错误的原因。
Please refer this MS DOC for more information.请参阅此MS DOC以获取更多信息。
We are assuming the Orchestrator.AssetManagement.Cmdlets
is bugged at this point, but have not found anything to say that it is.我们假设Orchestrator.AssetManagement.Cmdlets
在这一点上被窃听,但没有发现任何可以说它是。 To get around it we were going to use a runbook variable to store the password, but it needs the cmdlet to actually decode a secret/hidden value.为了解决这个问题,我们将使用 Runbook 变量来存储密码,但它需要 cmdlet 来实际解码秘密/隐藏值。
In the end, we used a key vault to store the password.最后,我们使用密钥保管库来存储密码。 The following is what was used as a workaround.以下是用作解决方法的内容。
$User = "AutomationUser"
$KeyVaultName = "KeyVault"
try {
$Password = (ConvertTo-SecureString (Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $User -AsPlainText) -AsPlainText -Force)
[PSCredential] $AutomationCredential = New-Object System.Management.Automation.PSCredential($User, $Password)
}
catch {
$ErrorMessage = "Unable to retrieve credentials for user: [${$User}]. $_"
throw $ErrorMessage
BREAK
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.