1

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

enter image description here

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

enter image description here

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
{
}
}
6
  • @Walter-MSFT - Thanks. Have added the script. Commented Apr 11, 2017 at 2:46
  • @Walter-MSFT - I feel this is not a script issue as the script works fine standalone. Commented Apr 11, 2017 at 2:48
  • I notice that when you execute your cmdlet local, you logon Azure using Add-AzureRmAccount and select subscription with select-azurermsubscription, they are ARM mode cmdlet. Commented Apr 11, 2017 at 2:54
  • Select-AzureSubscription -Default "XXXYYYZZZ" The cmdlet could execute successful on your local PC? I test in my lab, I get same error with you on build. Commented Apr 11, 2017 at 3:12
  • You could not add parameters after Default. Commented Apr 11, 2017 at 3:21

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

This works perfect. You are correct Since these are classic machines, I shuold not use Rm cmdlets. Switching to Select-AzureSubscription did the trick. Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.