我使用 PowerShell 創建了一個連接到 AzureAD 的腳本,該腳本應該自動連接到 AzureAD。下面是我的腳本。
$TenantId = ""
$SecFile = "C:\Azure-AD\Password.txt"
$SecUser = "C:\Azure-AD\UserName.txt"
$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $SecUser,
(Get-Content $SecFile | ConvertTo-SecureString)
Connect-AzureAD -TenantId $TenantId-credential $MyCredential
我正在使用以下行生成來加密我的密碼
(Get-Credential).Password | ConvertFrom-SecureString | Out-File "C:\AzureAD\Password.txt"
當我運行我的腳本時,我收到以下錯誤:
PS C:\Azure-AD> .\Azure-Connect.ps1
Connect-AzureAD : One or more errors occurred.:
At C:\BackupTableau\Azure-AD\Azure-Connect.ps1:10 char:1
Connect-AzureAD -TenantId $TenantId -credential $MyCredential
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AadAuthenticationFailedException
FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Connect-AzureAD: One or more errors occurred.
At C:\Azure-AD\Azure-Connect.ps1:10 char:1
Connect-AzureAD -TenantId $TenantId -credential $MyCredential
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AggregateException
FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Connect-AzureAD :
At C:\Azure-AD\Azure-Connect.ps1:10 char:1
Connect-AzureAD -TenantId $TenantId -credential $MyCredential
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AdalServiceException
FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Connect-AzureAD : Response status code does not indicate success: 404 (NotFound).
At C:\Azure-AD\Azure-Connect.ps1:10 char:1
Connect-AzureAD -TenantId $TenantId -credential $MyCredential
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], HttpRequestException
FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Connect-AzureAD : : Unknown error
At C:\Azure-AD\Azure-Connect.ps1:10 char:1
Connect-AzureAD -TenantId $TenantId -credential $MyCredential
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AdalException
FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Connect-AzureAD : One or more errors occurred.:
At C:\Azure-AD\Azure-Connect.ps1:10 char:1
Connect-AzureAD -TenantId $TenantId -credential $MyCredential
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : NotSpecified: (:) [Connect-AzureAD], AadAuthenticationFailedException
FullyQualifiedErrorId : Microsoft.Open.Azure.AD.CommonLibrary.AadAuthenticationFailedException,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
關于如何修復錯誤以使腳本成功運行的任何解決方案?
uj5u.com熱心網友回復:
您的腳本(最初)撰寫時用于(Get-Content $secFile ...) 從密碼檔案中檢索密碼,但僅將 $secUser 作為用戶名傳遞,這將是包含您的用戶的檔案名。
嘗試使用(Get-Content $secUser)從檔案中獲取用戶名的值。
我認為這會對你有所幫助。除此之外,我能否讓您對相對較新的模塊Microsoft.Powershell.SecretManagement, 和感興趣Microsoft.Powershell.SecretStore,它們允許您更安全地存盤您的憑據,而無需將它們作為純文本存盤在檔案中 - 我經常使用這些模塊來存盤我使用的個人訪問令牌例如,Azure DevOps REST API。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/319017.html
