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); } }
public override void ExecuteCmdlet() { string resourceGroupName; string vmScaleSetName; resourceGroupName = this.ResourceGroupName; vmScaleSetName = this.VMScaleSetName; var expand = new Microsoft.Rest.Azure.OData.ODataQuery <VirtualMachineScaleSetVM>(); expand.Expand = "instanceView"; var vmList = VirtualMachineScaleSetVMsClient.List(resourceGroupName, vmScaleSetName, expand); var resultList = vmList.ToList(); var nextPageLink = vmList.NextPageLink; while (!string.IsNullOrEmpty(nextPageLink)) { var pageResult = VirtualMachineScaleSetVMsClient.ListNext(nextPageLink); foreach (var pageItem in pageResult) { resultList.Add(pageItem); } nextPageLink = pageResult.NextPageLink; } List <VirtualMachineScaleSetVM> listOfVms = new List <VirtualMachineScaleSetVM>(resultList); Rest.Azure.AzureOperationResponse result = null; foreach (VirtualMachineScaleSetVM vm in listOfVms) { result = VirtualMachineScaleSetVMRunCommandsClient.BeginDeleteWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, vm.InstanceId, this.RunCommandName).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); }
protected void ExecuteVirtualMachineScaleSetVMListMethod(object[] invokeMethodInputParameters) { string resourceGroupName = (string)ParseParameter(invokeMethodInputParameters[0]); string virtualMachineScaleSetName = (string)ParseParameter(invokeMethodInputParameters[1]); Microsoft.Rest.Azure.OData.ODataQuery<VirtualMachineScaleSetVM> odataQuery = (Microsoft.Rest.Azure.OData.ODataQuery<VirtualMachineScaleSetVM>)ParseParameter(invokeMethodInputParameters[2]); string select = (string)ParseParameter(invokeMethodInputParameters[3]); var result = VirtualMachineScaleSetVMsClient.List(resourceGroupName, virtualMachineScaleSetName, odataQuery, select); 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); }
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, "Add")) { string resourceGroupName; string vmScaleSetName; switch (this.ParameterSetName) { case "ObjectParameter": resourceGroupName = GetResourceGroupName(this.VirtualMachineScaleSetVM.Id); vmScaleSetName = GetResourceName(this.VirtualMachineScaleSetVM.Id, "Microsoft.Compute/virtualMachineScaleSets", "virtualMachines"); break; default: resourceGroupName = this.ResourceGroupName; vmScaleSetName = this.VMScaleSetName; break; } VirtualMachineRunCommand vmruncommand; vmruncommand = new VirtualMachineRunCommand { OutputBlobUri = this.IsParameterBound(c => c.OutputBlobUri) ? this.OutputBlobUri : null, ErrorBlobUri = this.IsParameterBound(c => c.ErrorBlobUri) ? this.ErrorBlobUri : null, RunAsPassword = this.IsParameterBound(c => c.RunAsPassword) ? this.RunAsPassword.ToString() : null, RunAsUser = this.IsParameterBound(c => c.RunAsUser) ? this.RunAsUser : null, TimeoutInSeconds = this.IsParameterBound(c => c.TimeOutInSeconds) ? Convert.ToInt32(this.TimeOutInSeconds) : (int?)null, Location = this.IsParameterBound(c => c.Location) ? this.Location : null, AsyncExecution = this.IsParameterBound(c => c.AsyncExecution) ? this.AsyncExecution : null }; if (this.IsParameterBound(c => c.ScriptUri)) { vmruncommand.Source = new VirtualMachineRunCommandScriptSource { Script = this.IsParameterBound(c => c.Script) ? this.Script : null, ScriptUri = this.IsParameterBound(c => c.ScriptUri) ? this.ScriptUri : null, CommandId = this.IsParameterBound(c => c.CommandId) ? this.CommandId : null }; } else if (this.ScriptPath != null && this.IsParameterBound(c => c.ScriptPath)) { List <string> Script = new List <string>(); PathIntrinsics currentPath = SessionState.Path; var filePath = new System.IO.FileInfo(currentPath.GetUnresolvedProviderPathFromPSPath(this.ScriptPath)); string fileContent = Commands.Common.Authentication.Abstractions.FileUtilities.DataStore.ReadFileAsText(filePath.FullName); Script = fileContent.Split(new string[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries).ToList(); vmruncommand.Source = new VirtualMachineRunCommandScriptSource(this.Script, this.ScriptPath, this.CommandId); } if (this.Parameter != null) { var vParameter = new List <RunCommandInputParameter>(); foreach (var key in this.Parameter.Keys) { RunCommandInputParameter p = new RunCommandInputParameter(); p.Name = key.ToString(); p.Value = this.Parameter[key].ToString(); vParameter.Add(p); } vmruncommand.Parameters = vParameter; } else if (this.ProtectedParameter != null) { var vParameter = new List <RunCommandInputParameter>(); foreach (var key in this.ProtectedParameter.Keys) { RunCommandInputParameter p = new RunCommandInputParameter(); p.Name = key.ToString(); p.Value = this.ProtectedParameter[key].ToString(); vParameter.Add(p); } vmruncommand.ProtectedParameters = vParameter; } var expand = new Microsoft.Rest.Azure.OData.ODataQuery <VirtualMachineScaleSetVM>(); expand.Expand = "instanceView"; var vmList = VirtualMachineScaleSetVMsClient.List(resourceGroupName, vmScaleSetName, expand); var resultList = vmList.ToList(); var nextPageLink = vmList.NextPageLink; while (!string.IsNullOrEmpty(nextPageLink)) { var pageResult = VirtualMachineScaleSetVMsClient.ListNext(nextPageLink); foreach (var pageItem in pageResult) { resultList.Add(pageItem); } nextPageLink = pageResult.NextPageLink; } List <VirtualMachineScaleSetVM> listOfVms = new List <VirtualMachineScaleSetVM>(resultList); List <PSVirtualMachineRunCommand> output = new List <PSVirtualMachineRunCommand>(); foreach (VirtualMachineScaleSetVM vm in listOfVms) { var resultOfRunCmd = VirtualMachineScaleSetVMRunCommandsClient.BeginCreateOrUpdateAsync(resourceGroupName, vmScaleSetName, vm.InstanceId, this.Name, vmruncommand); var Pstemp = new PSVirtualMachineRunCommand(); ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineRunCommand, PSVirtualMachineRunCommand>(resultOfRunCmd.Result, Pstemp); output.Add(Pstemp); } WriteObject(output); } }); }