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:
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