简体   繁体   English

在 Azure DevOps 管道中运行 PowerShell 脚本

[英]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.我想在 Azure DevOps 管道中运行 PowerShell 脚本,但它给了我一个错误。 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: 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

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 .尝试使用Install-Module在管道任务中安装 Az(或 Az.Storage)模块。

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

暂无
暂无

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

相关问题 Azure devOps管道中的Powershell脚本 - Powershell script in azure devOps pipeline 在Azure DevOps管道中从PowerShell运行Terraform - Running Terraform from PowerShell in an Azure DevOps Pipeline 在运行 Azure DevOps 管道时,如果我们不给管道的 powershell 脚本中使用的变量任何值 - While running Azure DevOps pipeline, If we dont give any value to the variable which is used in powershell script of pipeline 在运行 Powershell 脚本的 Azure DevOps 管道中传递脚本参数 - Pass a script argument in Azure DevOps pipeline which runs a Powershell script 在 PowerShell 脚本中访问 Azure DevOps 管道中的安全文件 - Accessing secure file in Azure DevOps pipeline in PowerShell script 如何将 Powershell 脚本文件路径从 azure devops repo 传递到 Azure devops 构建管道 - how to pass Powershell script filepath from azure devops repo into Azure devops build pipeline Azure DevOps:如何从 Release Pipeline 中的 PowerShell 脚本构建 Azure Pipeline 检索构建工件? - Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline? 在 Azure DevOps 管道中运行 Azure powershell 命令 - Run Azure powershell commands in Azure devops pipeline 通过 YAML 发布管道运行 azure powershell 脚本 - Running azure powershell script through YAML release pipeline 在 Azure 中,负载均衡器详细信息在 csv 文件中使用 powershell 脚本在 ZCF04A02ZopsE37B774FC5361 的管道中 - In Azure,Loadbalancer details in to csv file using powershell script in pipeline of azure devops
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM