繁体   English   中英

在 Azure DevOps 管道中运行 PowerShell 脚本

[英]Running a PowerShell Script in Azure DevOps Pipeline

我想在 Azure DevOps 管道中运行 PowerShell 脚本,但它给了我一个错误。 如果有人可以指导我,将不胜感激。

流水线任务:

        - task: AzurePowerShell@5
          displayName: 'Create Private EndPoints'
          inputs:
            azureSubscription: 'ServiceConnection-SP'
            ScriptType: 'FilePath'
            ScriptPath: 'scripts/createPEndpoint.ps1'
            azurePowerShellVersion: 'LatestVersion'

PowerShell 脚本:

$storageResourceGroupName = 'RG-IAC-US'
$storageAccountName = 'iacstgus'
$virtualNetworkResourceGroupName = 'RG-CLOUD-US'
$virtualNetworkName = 'abcd-vnt-us'
$subnetName = 'StorageSubnet'
$location = 'eastus'

$privateEndpointResourceGroupName = 'RG-IaC-US'
$privateEndpointConnectionName = 'privend-iac-usconnection'
$privateEndpointName = 'privend-iac-us'

# get storage, vnet, subnet
$storage = Get-AzStorageAccount -ResourceGroupName $storageResourceGroupName -Name $storageAccountName
$vnet = Get-AzVirtualNetwork -ResourceGroupName $virtualNetworkResourceGroupName -Name $virtualNetworkName
$subnet = Get-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet

# create private link service connection for storage
$privEndConnection = New-AzPrivateLinkServiceConnection -Name $privateEndpointConnectionName -PrivateLinkServiceId $storage.Id -GroupId "blob"

# create private endpoint in subnet
New-AzPrivateEndpoint -ResourceGroupName $privateEndpointResourceGroupName -Name $privateEndpointName -Location $location -Subnet $subnet -PrivateLinkServiceConnection $privEndConnection

错误:

Get-AzStorageAccount : The term 'Get-AzStorageAccount' is not recognized as the name of a cmdlet, function, script 
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct 
and try again.

##[error]Script failed with exit code: 1

尝试使用Install-Module在管道任务中安装 Az(或 Az.Storage)模块。

检查这个 SO 问题: How do I import a PowerShell module for use by a pipeline task

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM