[英]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.