如何执行Reset-RoleInstance并等待操作完成...
我一直在尝试使用windows azure powershell命令行执行Reset-RoleInstance,后跟| Get-OperationStatus -WaitToComplete。
因此文档说“此操作异步执行。要确定Management服务是否已完成处理请求,请使用Reset-RoleInstance返回的操作ID调用Get-OperationStatus cmdlet,并可选择通过指定 - 等待完成 - WaitToComplete参数。“
我试过这个版本:
Reset-RoleInstance -ServiceName MyTodo -DeploymentSlot production -SubscriptionId $subsId -Certificate $cert –reboot | GetOperationStatus -WaitToComplete
但是在“GetOperationStatus”中有一个类型。所以当我用“Get-OperationStatus”替换时,PS会抱怨OperationId为空或空。
“Get-OperationStatus:无法验证参数'OperationId'的参数。参数 为null或为空。提供一个非null或空的参数,然后尝试使用comman 再一次。“
所以,接下来我尝试这个版本的PS脚本......
Reset-RoleInstance -ServiceName $serviceName -DeploymentSlot Production -InstanceName $i.InstanceName -SubscriptionId $subid -Certificate $cert -Reboot -OutVariable out | Get-OperationStatus -OperationId out.OperationId -WaitToComplete
这一次,Get-OperationStatus开始抛出错误......
Get-OperationStatus:HTTP状态代码:BadRequest - HTTP错误消息:未找到操作请求ID ...在Microsoft.WindowsAzure.Samples.ManagementTools.PowerShell.Services.Common.GetOperationStatusCommand中
Get-OperationStatus:对象引用未设置为对象的实例 ....在Microsoft.WindowsAzure.Samples.ManagementTools.PowerShell.Services.Common.GetOperationStatusCommand“*
我还设法打印$ out和OperationId实际上是null但是在输出的RoleInstances成员中有这个值... RoleInstances:{实例名称:MyService.MyWorker_IN_0 - 操作ID:6e87a07fb9a5474499aed3f9ebe99129 }
这是$ out变量的输出...... “RoleInstances:{实例名称:MyService.MyWorker_IN_0 - 操作ID:6e87a07fb9a5474499aed3f9ebe99129} ServiceName:...我的服务名称 SubscriptionId:...我的订阅ID 证书:...我的证书信息
OperationId: “
答案 0 :(得分:1)
使用 Reset-RoleInstance 时,它会重新启动/重新映像部署的实例。
整个操作本身没有 OperationId ,但个别 RoleInstances 有相应的< strong> OperationId 。
这是Reset-RoleInstance的输出结果:
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>
正如您所看到的, OperationId 最后是 NullOrEmpty 。所以你不应该等待 Reset-RoleInstance 的 OperationId ,但是应该等待 OperationIds 个人 RoleInstances 的em> 例如: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"