简体   繁体   中英

Running a PowerShell Script in Azure DevOps Pipeline

I want to run a PowerShell Script in Azure DevOps Pipeline but it's giving me an error. If anyone can guide me, it would be highly appreciated.

Pipeline Task:

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

PowerShell Script:

$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

Error:

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

Try to install the Az (or Az.Storage) module in a pipeline task with Install-Module .

Check this SO question: How do I import a PowerShell module for use by a pipeline task

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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