术语“ Get-AzureRmDataFactoryV2”未被识别为cmdlet的名称

时间:2019-02-20 07:02:13

标签: azure powershell azure-devops

我有powershell脚本,我们试图获取ADF v2和Get-AzureRmDataFactoryV2IntegrationRuntime的详细信息,并将Powershell脚本集成到了VSTS CI / CD管道中。但出现错误,例如无法识别这些术语。

但是,当我使用相同的脚本并运行到本地Powershell ISE时,它运行正常。 请共享相同的输入。请在下面找到我的脚本-

Write-Host "Login to Azure Subscription "  $SubscriptionName   -ForegroundColor Green

$azurePassword    = ConvertTo-SecureString $AccessKey -AsPlainText -Force
$psCred           = New-Object System.Management.Automation.PSCredential($clientID, $azurePassword)

Login-AzureRmAccount -Credential $psCred -ServicePrincipal -Tenant $TenantId

$subscription = Get-AzureRmSubscription

Write-Host "Set "  $SubscriptionName  " subscription as the current susbcription" -ForegroundColor Green
Get-AzureRmSubscription -subscriptionname $SubscriptionName | Set-AzureRmContext

$Datetime    = Get-Date -Format g 
$LogMsg      = "Getting Data Factory Staus ...  " 
$LogMessage  = $LogMsg +" "+ $Datetime  
LogWrite $LogMessage

$dfExists = Get-AzureRmDataFactoryV2 -Name $DataFactoryName -ResourceGroupName $ResourceGroupName -ErrorAction Ignore

if($dfExists -eq $null )
{
    $Datetime    = Get-Date -Format g 
    $LogMsg      = "Deploying Data Factory  : "  + $DataFactoryName + " "
    $LogMessage  = $LogMsg +" "+ $Datetime  
    LogWrite $LogMessage

   #Set-AzureRmDataFactoryV2 -ResourceGroupName $ResourceGroupName -Name $DataFactoryName -Location $Location -Force -ErrorAction Stop
}

[System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
$ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer -ErrorAction Stop

$Datetime    = Get-Date -Format g 
$LogMsg      = "Getting Integration Runtime  Status ...  " 
$LogMessage  = $LogMsg +" "+ $Datetime  
LogWrite $LogMessage

Write-Host "Getting Integration Runtime to Deploy..."  -ForegroundColor Green

$irExists = Get-AzureRmDataFactoryV2IntegrationRuntime -ResourceGroupName $ResourceGroupName  -DataFactoryName $DataFactoryName  -ErrorAction Stop | Where-Object Name -eq $ADFGatewayName

if ($irExists -eq $null)
{
    $Datetime    = Get-Date -Format g 
    $LogMsg      = "Deploying Integration Runtime : " +  $ADFGatewayName 
    $LogMessage  = $LogMsg +" "+ $Datetime  
    LogWrite $LogMessage

    Set-AzureRmDataFactoryV2IntegrationRuntime -ResourceGroupName $ResourceGroupName  -DataFactoryName $DataFactoryName -Name $ADFGatewayName   -Type "SelfHosted"                          
}

2 个答案:

答案 0 :(得分:1)

这是我刚刚尝试过的方法,对我有用:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module AzureRM.DataFactoryV2 -Force -AllowClobber

这必须在脚本的顶部。您的错误清楚地表明,由于它是管道,因此它试图向您提示某些内容,但是不能。

enter image description here

答案 1 :(得分:0)

我收到来自@ 4c74356b41的修复程序下一个错误:Windows PowerShell处于非交互模式。读取和提示功能不可用。

又有一条说明可以帮助我使其变得可行(https://github.com/PowerShell/PowerShellGet/issues/79):

Install-PackageProvider nuget -force
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module AzureRM.DataFactoryV2 -Force -AllowClobber