protected void ExecuteVirtualMachineScaleSetVMUpdateMethod(object[] invokeMethodInputParameters) { string resourceGroupName = (string)ParseParameter(invokeMethodInputParameters[0]); string vmScaleSetName = (string)ParseParameter(invokeMethodInputParameters[1]); string instanceId = (string)ParseParameter(invokeMethodInputParameters[2]); VirtualMachineScaleSetVM parameters = (VirtualMachineScaleSetVM)ParseParameter(invokeMethodInputParameters[3]); var result = VirtualMachineScaleSetVMsClient.Update(resourceGroupName, vmScaleSetName, instanceId, parameters); WriteObject(result); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.VMScaleSetName, VerbsData.Update)) { string resourceGroupName; string vmScaleSetName; string instanceId; switch (this.ParameterSetName) { case "ResourceIdParameter": resourceGroupName = GetResourceGroupName(this.ResourceId); vmScaleSetName = GetResourceName(this.ResourceId, "Microsoft.Compute/VirtualMachineScaleSets", "virtualMachines"); instanceId = GetInstanceId(this.ResourceId, "Microsoft.Compute/VirtualMachineScaleSets", "virtualMachines"); break; case "ObjectParameter": resourceGroupName = GetResourceGroupName(this.VirtualMachineScaleSetVM.Id); vmScaleSetName = GetResourceName(this.VirtualMachineScaleSetVM.Id, "Microsoft.Compute/VirtualMachineScaleSets", "virtualMachines"); instanceId = GetInstanceId(this.VirtualMachineScaleSetVM.Id, "Microsoft.Compute/VirtualMachineScaleSets", "virtualMachines"); break; default: resourceGroupName = this.ResourceGroupName; vmScaleSetName = this.VMScaleSetName; instanceId = this.InstanceId; break; } VirtualMachineScaleSetVM parameters = new VirtualMachineScaleSetVM(); ComputeAutomationAutoMapperProfile.Mapper.Map <PSVirtualMachineScaleSetVM, VirtualMachineScaleSetVM>(this.VirtualMachineScaleSetVM, parameters); if (this.ParameterSetName != "ObjectParameter") { parameters = VirtualMachineScaleSetVMsClient.Get(resourceGroupName, vmScaleSetName, instanceId); } if (this.DataDisk != null) { if (parameters.StorageProfile == null) { parameters.StorageProfile = new StorageProfile(); } if (parameters.StorageProfile.DataDisks == null) { parameters.StorageProfile.DataDisks = new List <DataDisk>(); } foreach (var d in this.DataDisk) { parameters.StorageProfile.DataDisks.Add(d); } } var result = VirtualMachineScaleSetVMsClient.Update(resourceGroupName, vmScaleSetName, instanceId, parameters); var psObject = new PSVirtualMachineScaleSetVM(); ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineScaleSetVM, PSVirtualMachineScaleSetVM>(result, psObject); WriteObject(psObject); } }); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.VMScaleSetName, VerbsData.Update)) { string resourceGroupName; string vmScaleSetName; string instanceId; switch (this.ParameterSetName) { case ResourceIdParameterSet: resourceGroupName = GetResourceGroupName(this.ResourceId); vmScaleSetName = GetResourceName(this.ResourceId, "Microsoft.Compute/virtualMachineScaleSets", "virtualMachines"); instanceId = GetInstanceId(this.ResourceId, "Microsoft.Compute/virtualMachineScaleSets", "virtualMachines"); break; case ObjectParameterSet: resourceGroupName = GetResourceGroupName(this.VirtualMachineScaleSetVM.Id); vmScaleSetName = GetResourceName(this.VirtualMachineScaleSetVM.Id, "Microsoft.Compute/virtualMachineScaleSets", "virtualMachines"); instanceId = GetInstanceId(this.VirtualMachineScaleSetVM.Id, "Microsoft.Compute/virtualMachineScaleSets", "virtualMachines"); break; default: resourceGroupName = this.ResourceGroupName; vmScaleSetName = this.VMScaleSetName; instanceId = this.InstanceId; break; } VirtualMachineScaleSetVM parameters = new VirtualMachineScaleSetVM(); ComputeAutomationAutoMapperProfile.Mapper.Map <PSVirtualMachineScaleSetVM, VirtualMachineScaleSetVM>(this.VirtualMachineScaleSetVM, parameters); if (this.IsParameterBound(c => c.UserData)) { parameters = VirtualMachineScaleSetVMsClient.Get(resourceGroupName, vmScaleSetName, instanceId, UserDataExpand); } else if (this.ParameterSetName != ObjectParameterSet) { parameters = VirtualMachineScaleSetVMsClient.Get(resourceGroupName, vmScaleSetName, instanceId); } if (this.DataDisk != null) { if (parameters.StorageProfile == null) { parameters.StorageProfile = new StorageProfile(); } if (parameters.StorageProfile.DataDisks == null) { parameters.StorageProfile.DataDisks = new List <DataDisk>(); } foreach (var d in this.DataDisk) { parameters.StorageProfile.DataDisks.Add(d); } } if (this.IsParameterBound(c => c.ProtectFromScaleIn)) { if (parameters.ProtectionPolicy == null) { parameters.ProtectionPolicy = new VirtualMachineScaleSetVMProtectionPolicy(); } parameters.ProtectionPolicy.ProtectFromScaleIn = this.ProtectFromScaleIn; } if (this.IsParameterBound(c => c.ProtectFromScaleSetAction)) { if (parameters.ProtectionPolicy == null) { parameters.ProtectionPolicy = new VirtualMachineScaleSetVMProtectionPolicy(); } parameters.ProtectionPolicy.ProtectFromScaleSetActions = this.ProtectFromScaleSetAction; } if (this.IsParameterBound(c => c.UserData)) { if (!ValidateBase64EncodedString.ValidateStringIsBase64Encoded(this.UserData)) { this.UserData = ValidateBase64EncodedString.EncodeStringToBase64(this.UserData); this.WriteInformation(ValidateBase64EncodedString.UserDataEncodeNotification, new string[] { "PSHOST" }); } parameters.UserData = this.UserData; } var result = VirtualMachineScaleSetVMsClient.Update(resourceGroupName, vmScaleSetName, instanceId, parameters); var psObject = new PSVirtualMachineScaleSetVM(); ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineScaleSetVM, PSVirtualMachineScaleSetVM>(result, psObject); WriteObject(psObject); } }); }