Unable to Start an Azure VM using Powershell script. We get Parameter set cannot be resolved using the specified named parameters

强颜欢笑 提交于 2019-12-11 05:46:35

问题


We use powershell script to start and stop the VMs using the build job. Please see the screenshot of the build job below

It is a simple powershell script to start an VM. The issue is when this job runs, we are getting an error and the build fails. We get Parameter set cannot be resolved using the specified named parameters

But when we run it locally using the powershell console, the VMs get started.

Please find the error screenshot below

Am I missing something here.. Any help would be very much appreciated.

EDIT 1 Powershell script

$machines = @("machinename")
Select-AzureSubscription -Default "XXXYYYZZZ"

Foreach ($machine in $machines)
{   
Try
{
    Start-AzureVM -ServiceName $machine -Name $machine
}
Catch
{
}
}

回答1:


I check your screenshot, I find you want to stop classic VMs. However, you logon Azure with cmdlet Add-AzureRmAccount and select subscription with cmdlet select-azurermsubscription, am I right? The two cmdlets are ARM mode cmdlets, you should use classic mode cmdlets.

Add-AzureAccount

According to your error, you could not use Select-AzureSubscription -Default "XXXYYYZZZ". Default could not add parameters. More information please refer to this link.

Try to use the following cmdlets.

Get-AzureSubscription

Select-AzureSubscription -SubscriptionName <YourSubscriptionName> -Default


来源:https://stackoverflow.com/questions/43335891/unable-to-start-an-azure-vm-using-powershell-script-we-get-parameter-set-cannot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!