簡體   English   中英

適用於 PowerShell 7 的 Azure 自動化混合工作者 Get-AutomationPSCredential

[英]Azure Automation Hybrid-Worker Get-AutomationPSCredential for PowerShell 7

我們正在將一些 Azure 自動化混合工作器腳本移至 PowerShell 7.1。 為此,在 PowerShell 5.1 中工作的命令之一是: [PSCredential] $AutomationCredential = Get-AutomationPSCredential -Name 'abcdef' 當我們在 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'

我們已將導入模塊添加到代碼中,但我們得到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

我們確實在沙盒區域中的混合工作器上找到 Orchestrator.AssetManagement.Cmdlets。 我們知道這個模塊是在安裝 hybrid-worker 時加載的 ( https://docs.microsoft.com/en-us/azure/automation/shared-resources/modules#internal-cmdlets )。

基於微軟官方文檔

'Get-AutomationPSCredential目前支持直到Azure powershell 6.6.0

在此處輸入圖片說明

注意:Powershell 7.1 仍處於預覽階段,所以這可能是錯誤的原因。

請參閱此MS DOC以獲取更多信息。

我們假設Orchestrator.AssetManagement.Cmdlets在這一點上被竊聽,但沒有發現任何可以說它是。 為了解決這個問題,我們將使用 Runbook 變量來存儲密碼,但它需要 cmdlet 來實際解碼秘密/隱藏值。

最后,我們使用密鑰保管庫來存儲密碼。 以下是用作解決方法的內容。

$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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM