コード例 #1
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.VMScaleSetName, VerbsCommon.Set))
                {
                    string resourceGroupName = this.ResourceGroupName;
                    string vmScaleSetName    = this.VMScaleSetName;
                    string instanceId        = this.InstanceId;

                    Rest.Azure.AzureOperationResponse result = null;
                    if (this.ParameterSetName.Equals("FriendMethod"))
                    {
                        result = VirtualMachineScaleSetVMsClient.ReimageAllWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
                    }
                    else if (this.ParameterSetName.Equals("RedeployMethodParameter"))
                    {
                        result = VirtualMachineScaleSetVMsClient.RedeployWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
                    }
                    else if (this.ParameterSetName.Equals("PerformMaintenanceMethodParameter"))
                    {
                        result = VirtualMachineScaleSetVMsClient.PerformMaintenanceWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
                    }
                    else if (this.ParameterSetName.Equals("SimulateEvictionMethodParameter"))
                    {
                        result = VirtualMachineScaleSetVMsClient.SimulateEvictionWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
                    }
                    else
                    {
                        result = VirtualMachineScaleSetVMsClient.ReimageWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
                    }

                    PSOperationStatusResponse output = new PSOperationStatusResponse
                    {
                        StartTime = this.StartTime,
                        EndTime   = DateTime.Now
                    };

                    if (result != null && result.Request != null && result.Request.RequestUri != null)
                    {
                        output.Name = GetOperationIdFromUrlString(result.Request.RequestUri.ToString());
                    }

                    WriteObject(output);
                }
            });
        }