protected void ExecuteVirtualMachineScaleSetVMGetMethod(object[] invokeMethodInputParameters) { string resourceGroupName = (string)ParseParameter(invokeMethodInputParameters[0]); string vmScaleSetName = (string)ParseParameter(invokeMethodInputParameters[1]); string instanceId = (string)ParseParameter(invokeMethodInputParameters[2]); if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmScaleSetName) && !string.IsNullOrEmpty(instanceId)) { var result = VirtualMachineScaleSetVMsClient.Get(resourceGroupName, vmScaleSetName, instanceId); WriteObject(result); } else if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmScaleSetName)) { var result = VirtualMachineScaleSetVMsClient.List(resourceGroupName, vmScaleSetName); var resultList = result.ToList(); var nextPageLink = result.NextPageLink; while (!string.IsNullOrEmpty(nextPageLink)) { var pageResult = VirtualMachineScaleSetVMsClient.ListNext(nextPageLink); foreach (var pageItem in pageResult) { resultList.Add(pageItem); } nextPageLink = pageResult.NextPageLink; } WriteObject(resultList, true); } }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { string resourceGroupName = this.ResourceGroupName; string vmScaleSetName = this.VMScaleSetName; string instanceId = this.InstanceId; if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmScaleSetName) && !string.IsNullOrEmpty(instanceId)) { if (this.ParameterSetName.Equals("FriendMethod")) { var result = VirtualMachineScaleSetVMsClient.GetInstanceView(resourceGroupName, vmScaleSetName, instanceId); var psObject = new PSVirtualMachineScaleSetVMInstanceView(); ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineScaleSetVMInstanceView, PSVirtualMachineScaleSetVMInstanceView>(result, psObject); WriteObject(psObject); } else { var result = VirtualMachineScaleSetVMsClient.Get(resourceGroupName, vmScaleSetName, instanceId); var psObject = new PSVirtualMachineScaleSetVM(); ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineScaleSetVM, PSVirtualMachineScaleSetVM>(result, psObject); WriteObject(psObject); } } else if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmScaleSetName)) { var result = VirtualMachineScaleSetVMsClient.List(resourceGroupName, vmScaleSetName); var resultList = result.ToList(); var nextPageLink = result.NextPageLink; while (!string.IsNullOrEmpty(nextPageLink)) { var pageResult = VirtualMachineScaleSetVMsClient.ListNext(nextPageLink); foreach (var pageItem in pageResult) { resultList.Add(pageItem); } nextPageLink = pageResult.NextPageLink; } var psObject = new List <PSVirtualMachineScaleSetVMList>(); foreach (var r in resultList) { psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineScaleSetVM, PSVirtualMachineScaleSetVMList>(r)); } WriteObject(psObject, true); } }); }
protected void ExecuteVirtualMachineScaleSetVMGetMethod(object[] invokeMethodInputParameters) { string resourceGroupName = (string)ParseParameter(invokeMethodInputParameters[0]); string vmScaleSetName = (string)ParseParameter(invokeMethodInputParameters[1]); string instanceId = (string)ParseParameter(invokeMethodInputParameters[2]); if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmScaleSetName) && !string.IsNullOrEmpty(instanceId)) { var result = VirtualMachineScaleSetVMsClient.Get(resourceGroupName, vmScaleSetName, instanceId); WriteObject(result); } else if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmScaleSetName)) { var result = VirtualMachineScaleSetVMsClient.List(resourceGroupName, vmScaleSetName); WriteObject(result); } }
protected void ExecuteVirtualMachineScaleSetVMGetMethod(object[] invokeMethodInputParameters) { string resourceGroupName = (string)ParseParameter(invokeMethodInputParameters[0]); string vmScaleSetName = (string)ParseParameter(invokeMethodInputParameters[1]); string instanceId = (string)ParseParameter(invokeMethodInputParameters[2]); if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmScaleSetName) && !string.IsNullOrEmpty(instanceId)) { var result = VirtualMachineScaleSetVMsClient.Get(resourceGroupName, vmScaleSetName, instanceId); var psObject = new PSVirtualMachineScaleSetVM(); Mapper.Map <VirtualMachineScaleSetVM, PSVirtualMachineScaleSetVM>(result, psObject); WriteObject(psObject); } else if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmScaleSetName)) { var result = VirtualMachineScaleSetVMsClient.List(resourceGroupName, vmScaleSetName); var psObject = new List <PSVirtualMachineScaleSetVMList>(); foreach (var r in result) { psObject.Add(Mapper.Map <VirtualMachineScaleSetVM, PSVirtualMachineScaleSetVMList>(r)); } 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 "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); } }); }