public void RemoveVMImageProcess()
        {
            try
            {
                Uri mediaLink = null;
                if (this.DeleteVHD.IsPresent)
                {
                    // Get the location of the underlying VHD
                    using (new OperationContextScope(Channel.ToContextChannel()))
                    {
                        var image = this.RetryCall(s => this.Channel.GetOSImage(s, this.ImageName));
                        mediaLink = image.MediaLink;
                    }
                }

                // Remove the image from the image repository
                using (new OperationContextScope(Channel.ToContextChannel()))
                {
                    ExecuteClientAction(null, CommandRuntime.ToString(), s => this.Channel.DeleteOSImage(s, this.ImageName));
                }

                if (this.DeleteVHD.IsPresent)
                {
                    // Remove the underlying VHD from the blob storage
                    Disks.RemoveVHD(this.Channel, CurrentSubscription.SubscriptionId, mediaLink);
                }
            }
            catch (ServiceManagementClientException ex)
            {
                this.WriteErrorDetails(ex);
            }
        }
        public void RemoveVMImageProcess()
        {
            Func <string, OSImage> func   = null;
            Action <string>        action = null;

            try
            {
                Uri             mediaLink = null;
                SwitchParameter deleteVHD = this.DeleteVHD;
                if (deleteVHD.IsPresent)
                {
                    using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                    {
                        RemoveAzureVMImageCommand removeAzureVMImageCommand = this;
                        if (func == null)
                        {
                            func = (string s) => base.Channel.GetOSImage(s, this.ImageName);
                        }
                        OSImage oSImage = ((CmdletBase <IServiceManagement>)removeAzureVMImageCommand).RetryCall <OSImage>(func);
                        mediaLink = oSImage.MediaLink;
                    }
                }
                using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                {
                    RemoveAzureVMImageCommand removeAzureVMImageCommand1 = this;
                    if (action == null)
                    {
                        action = (string s) => base.Channel.DeleteOSImage(s, this.ImageName);
                    }
                    ((CmdletBase <IServiceManagement>)removeAzureVMImageCommand1).RetryCall(action);
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                    managementOperationContext.set_OperationId(operation.OperationTrackingId);
                    managementOperationContext.set_OperationStatus(operation.Status);
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                }
                SwitchParameter switchParameter = this.DeleteVHD;
                if (switchParameter.IsPresent)
                {
                    Disks.RemoveVHD(base.Channel, base.get_CurrentSubscription().get_SubscriptionId(), mediaLink);
                }
            }
            catch (CommunicationException communicationException1)
            {
                CommunicationException communicationException = communicationException1;
                this.WriteErrorDetails(communicationException);
            }
        }