Pra*_*eep 5 azure-powershell azure-devops azure-pipelines
我正在尝试通过使用内联模式的 PowerShell 任务在 Azure DevOps 管道中执行以下 PowerShell 脚本。
$clientId= "xxxxxxxxx"
$clientSecret= "xxxxxxx"
$subscriptionId= "xxxxxxxx"
$tenantId= "xxxxxxxxxxxxx"
# sign in
Write-Host "Logging in...";
$SecurePassword = $clientSecret | ConvertTo-SecureString -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $clientId, $SecurePassword
Connect-AzAccount -ServicePrincipal -Credential $cred-Tenant $tenantId
# set azure context with subscriptionId
Set-AzContext -SubscriptionId $subscriptionId
# select subscription
Write-Host "Selecting subscription '$subscriptionId'";
Select-AzSubscription -SubscriptionId $subscriptionId;
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Connect-AzAccount :术语“Connect-AzAccount”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
Yas*_*ala 61
该命令所属的模块 - 'Az' 可能不存在/必须导入。在这种情况下,
情况1
Install-Module AzImport-Module AzConnect-AzAccount现在应该可以工作了。对于情况 2 导入模块使用 -Import-Module Az.Accounts
Wit*_*ult 25
对我来说,这就是问题所在 - AzureRM和AZ都已安装。
在 Windows PowerShell 中,检查是否已安装 AzureRM:
Get-InstalledModule -name AzureRM
使用命令Uninstall-module -name AzureRM将其删除。
如果上面的命令不起作用,请使用下面的命令
Get-Module -ListAvailable | Where-Object {$_.Name -like 'AzureRM*'} | Uninstall-Module
下一页->
将 powershell 的executionPolicy 设置为RemoteSigned
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
下一页->
在 Windows PowerShell 中安装 Az PowerShell 模块
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
下一页->
输入Connect-AzAccount并完成签名流程。
Aug*_*ste 11
就我而言,AZ 未成功安装,因为某些 AZ 模块已随 AzureRM 安装。我添加了参数-AllowClobber,现在所有 AZ 模块均已安装。
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -AllowClobber
Run Code Online (Sandbox Code Playgroud)
使用命令卸载 AzureRMUninstall-AzureRM也可能是一个很好的解决方案,因为您将不再使用 AzureRM。Microsoft 有时会在 2024 年 2 月停止支持它。
| 归档时间: |
|
| 查看次数: |
6093 次 |
| 最近记录: |