Using powershell windows azure commandlets, how to I execute Reset-RoleInstance and wait for the operation to complete

How to I execute Reset-RoleInstance and wait for the operation to complete...

I have been attempting to use the windows azure powershell commandlets to execute Reset-RoleInstance followed by | Get-OperationStatus -WaitToComplete.

So the documentation says "This operation executes asynchronously. To determine whether the Management service has finished processing the request, call the Get-OperationStatus cmdlet with the operation ID returned by Reset-RoleInstance, and optionally wait for completion by specifying the –WaitToComplete parameter."

I have tried this version:

Reset-RoleInstance -ServiceName MyTodo -DeploymentSlot production -SubscriptionId $subsId -Certificate $cert –reboot | GetOperationStatus -WaitToComplete

but this has a type in "GetOperationStatus". So when I replace with "Get-OperationStatus", PS complains that OperationId is null or empty.

"Get-OperationStatus : Cannot validate argument on parameter 'OperationId'. The argument is null or empty. Supply an argument that is not null or empty and then try the comman d again."

So, next I try this version of the PS script...

Reset-RoleInstance -ServiceName $serviceName -DeploymentSlot Production -InstanceName $i.InstanceName -SubscriptionId $subid -Certificate $cert -Reboot -OutVariable out | Get-OperationStatus -OperationId out.OperationId -WaitToComplete

This time, Get-OperationStatus starts throwing errors...

Get-OperationStatus : HTTP Status Code: BadRequest - HTTP Error Message: The operation request ID was not found ... in Microsoft.WindowsAzure.Samples.ManagementTools.PowerShell.Services.Common.GetOperationStatusCommand

Get-OperationStatus : Object reference not set to an instance of an object.... in Microsoft.WindowsAzure.Samples.ManagementTools.PowerShell.Services.Common.GetOperationStatusCommand"*

I have also managed to print $out and OperationId is infact null BUT in the RoleInstances member of the output there is this value... RoleInstances : {Instance Name: MyService.MyWorker_IN_0 - Operation Id: 6e87a07fb9a5474499aed3f9ebe99129}

Here is the output of the $out variable... "RoleInstances : {Instance Name: MyService.MyWorker_IN_0 - Operation Id: 6e87a07fb9a5474499aed3f9ebe99129} ServiceName : ... my service name SubscriptionId : ... my subscription id Certificate : ... my certificate info

OperationId : "


When you use Reset-RoleInstance, it either reboots/reimages the instances of the deployment. The whole operation as such does not have an OperationId but the individual RoleInstances have a corresponding OperationId each.

This is how the output of Reset-RoleInstance looks like:

PS > $operation = Reset-RoleInstance -ServiceName "MyServiceName" -DeploymentSlot "production" -Restart -SubscriptionId "MySubscriptionID" -Certificate $cert
PS > $operation
RoleInstances  : { Instance Name: MyInst1 - Operation Id: OpId1, 
-                  Instance Name: MyInst2 - Operation Id: OpId2 }

ServiceName    : MyServiceName
SubscriptionId : MySubscriptionID
Certificate    : [Subject]
-                ------- blah --------

-                [Issuer]
-                ------- blah --------

-                [Serial Number]
-                ------- blah --------

-                [Not Before]
-                ------- blah --------

-                [Not After]
-                ------- blah --------

-                [Thumbprint]
-                ------- blah --------

OperationId    : <NullOrEmpty>

As you can see the OperationId at the end is NullOrEmpty. So you should not be waiting on the OperationId of the Reset-RoleInstance but should be waiting on the OperationIds of the individual RoleInstances Eg: OpId1, OpId2

PS > Write-Host "Rebooting the instances"
PS > $operation = Reset-RoleInstance -Reboot -SubscriptionId $SubscriptionId -ServiceName $ServiceName -DeploymentSlot "Production" -Certificate $certificate
PS > Write-Host "Waiting for all reboot operations to complete..."
PS > $operation.RoleInstances | % { Get-OperationStatus -OperationId $_.OperationId -WaitToComplete -SubscriptionId $SubscriptionId -Certificate $certificate }
PS > Write-Host "All role-instances have been rebooted"

Need Your Help

How to remove a specific view controller from uinavigationcontroller stack?

iphone objective-c uinavigationcontroller navigation

I have a uinavigationcontroller. After logged in i want to remove viewcontrollers like RegisterViewController,LoginViewController etc from UInavigationcontroller stack..

Put watermark on image that load from DB - php


I had the below code that load image from DB. There are more than 600 rows of image has been inserted into the DB. I need the script that can perform these action: