public override void ExecuteCmdlet() { WriteWarning("New-AzureRmVMConfig: A property of the output of this cmdlet will change in an upcoming breaking change release. " + "The StorageAccountType property for a DataDisk will return Standard_LRS and Premium_LRS"); var vm = new PSVirtualMachine { Name = this.VMName, AvailabilitySetReference = string.IsNullOrEmpty(this.AvailabilitySetId) ? null : new SubResource { Id = this.AvailabilitySetId }, LicenseType = this.LicenseType, Identity = this.AssignIdentity.IsPresent ? new VirtualMachineIdentity(null, null, ResourceIdentityType.SystemAssigned) : null, Tags = this.Tags != null?this.Tags.ToDictionary() : null, Zones = this.Zone, }; if (this.IdentityType != null) { vm.Identity = new VirtualMachineIdentity(null, null, this.IdentityType); if (this.IdentityId != null) { vm.Identity.IdentityIds = this.IdentityId; } } if (!string.IsNullOrEmpty(this.VMSize)) { vm.HardwareProfile = new HardwareProfile(); vm.HardwareProfile.VmSize = this.VMSize; } WriteObject(vm); }
public override void ExecuteCmdlet() { var vm = new PSVirtualMachine { Name = this.VMName, AvailabilitySetReference = string.IsNullOrEmpty(this.AvailabilitySetId) ? null : new SubResource { Id = this.AvailabilitySetId }, LicenseType = this.LicenseType, Identity = this.AssignIdentity.IsPresent ? new VirtualMachineIdentity(null, null, ResourceIdentityType.SystemAssigned) : null, Tags = this.Tags != null?this.Tags.ToDictionary() : null, Zones = this.Zone, }; if (this.IdentityType != null) { vm.Identity = new VirtualMachineIdentity(null, null, ResourceIdentityType.SystemAssigned); } if (!string.IsNullOrEmpty(this.VMSize)) { vm.HardwareProfile = new HardwareProfile(); vm.HardwareProfile.VmSize = this.VMSize; } WriteObject(vm); }
public override void ExecuteCmdlet() { var vm = new PSVirtualMachine { Name = this.VMName, AvailabilitySetReference = string.IsNullOrEmpty(this.AvailabilitySetId) ? null : new SubResource { Id = this.AvailabilitySetId }, LicenseType = this.LicenseType, Identity = this.AssignIdentity.IsPresent ? new VirtualMachineIdentity(null, null, ResourceIdentityType.SystemAssigned) : null, Tags = this.Tags != null?this.Tags.ToDictionary() : null, Zones = this.Zone, }; if (this.IsParameterBound(c => c.IdentityType)) { vm.Identity = new VirtualMachineIdentity(null, null, this.IdentityType); } if (this.IsParameterBound(c => c.IdentityId)) { if (vm.Identity == null) { vm.Identity = new VirtualMachineIdentity(); } vm.Identity.UserAssignedIdentities = new Dictionary <string, VirtualMachineIdentityUserAssignedIdentitiesValue>(); foreach (var id in this.IdentityId) { vm.Identity.UserAssignedIdentities.Add(id, new VirtualMachineIdentityUserAssignedIdentitiesValue()); } } if (!string.IsNullOrEmpty(this.VMSize)) { vm.HardwareProfile = new HardwareProfile(); vm.HardwareProfile.VmSize = this.VMSize; } if (this.EnableUltraSSD.IsPresent) { vm.AdditionalCapabilities = new AdditionalCapabilities(true); } if (this.IsParameterBound(c => c.ProximityPlacementGroupId)) { vm.ProximityPlacementGroup = new SubResource(this.ProximityPlacementGroupId); } if (this.MyInvocation.BoundParameters.ContainsKey("HostId")) { vm.Host = new SubResource(this.HostId); } WriteObject(vm); }
protected void ExecuteVirtualMachineGetMethod(object[] invokeMethodInputParameters) { string resourceGroupName = (string)ParseParameter(invokeMethodInputParameters[0]); string vmName = (string)ParseParameter(invokeMethodInputParameters[1]); InstanceViewTypes?expand = (InstanceViewTypes?)ParseParameter(invokeMethodInputParameters[2]); if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmName)) { var result = VirtualMachinesClient.Get(resourceGroupName, vmName, expand); var psObject = new PSVirtualMachine(); Mapper.Map <VirtualMachine, PSVirtualMachine>(result, psObject); WriteObject(psObject); } else if (!string.IsNullOrEmpty(resourceGroupName)) { var result = VirtualMachinesClient.List(resourceGroupName); var resultList = result.ToList(); var nextPageLink = result.NextPageLink; while (!string.IsNullOrEmpty(nextPageLink)) { var pageResult = VirtualMachinesClient.ListNext(nextPageLink); foreach (var pageItem in pageResult) { resultList.Add(pageItem); } nextPageLink = pageResult.NextPageLink; } var psObject = new List <PSVirtualMachineList>(); foreach (var r in resultList) { psObject.Add(Mapper.Map <VirtualMachine, PSVirtualMachineList>(r)); } WriteObject(psObject, true); } else { var result = VirtualMachinesClient.ListAll(); var resultList = result.ToList(); var nextPageLink = result.NextPageLink; while (!string.IsNullOrEmpty(nextPageLink)) { var pageResult = VirtualMachinesClient.ListAllNext(nextPageLink); foreach (var pageItem in pageResult) { resultList.Add(pageItem); } nextPageLink = pageResult.NextPageLink; } var psObject = new List <PSVirtualMachineList>(); foreach (var r in resultList) { psObject.Add(Mapper.Map <VirtualMachine, PSVirtualMachineList>(r)); } WriteObject(psObject, true); } }
public override void ExecuteCmdlet() { var vm = new PSVirtualMachine { Name = this.VMName, AvailabilitySetReference = string.IsNullOrEmpty(this.AvailabilitySetId) ? null : new AvailabilitySetReference { ReferenceUri = this.AvailabilitySetId } }; if (!string.IsNullOrEmpty(this.VMSize)) { vm.HardwareProfile = new HardwareProfile(); vm.HardwareProfile.VirtualMachineSize = this.VMSize; } WriteObject(vm); }
public override void ExecuteCmdlet() { var vm = new PSVirtualMachine { Name = this.VMName, AvailabilitySetReference = string.IsNullOrEmpty(this.AvailabilitySetId) ? null : new SubResource { Id = this.AvailabilitySetId }, LicenseType = this.LicenseType, Identity = null, Tags = this.Tags != null?this.Tags.ToDictionary() : null, Zones = this.Zone, EvictionPolicy = this.EvictionPolicy, Priority = this.Priority }; if (this.IsParameterBound(c => c.IdentityType)) { vm.Identity = new VirtualMachineIdentity(null, null, this.IdentityType); } if (this.IsParameterBound(c => c.IdentityId)) { if (vm.Identity == null) { vm.Identity = new VirtualMachineIdentity(); } vm.Identity.UserAssignedIdentities = new Dictionary <string, VirtualMachineIdentityUserAssignedIdentitiesValue>(); foreach (var id in this.IdentityId) { vm.Identity.UserAssignedIdentities.Add(id, new VirtualMachineIdentityUserAssignedIdentitiesValue()); } } if (!string.IsNullOrEmpty(this.VMSize)) { vm.HardwareProfile = new HardwareProfile(); vm.HardwareProfile.VmSize = this.VMSize; } if (this.EnableUltraSSD.IsPresent) { vm.AdditionalCapabilities = new AdditionalCapabilities(true); } if (this.IsParameterBound(c => c.ProximityPlacementGroupId)) { vm.ProximityPlacementGroup = new SubResource(this.ProximityPlacementGroupId); } if (this.IsParameterBound(c => c.HostId)) { vm.Host = new SubResource(this.HostId); } if (this.IsParameterBound(c => c.VmssId)) { vm.VirtualMachineScaleSet = new SubResource(this.VmssId); } if (this.IsParameterBound(c => c.MaxPrice)) { vm.BillingProfile = new BillingProfile(this.MaxPrice); } if (this.EncryptionAtHost.IsPresent) { if (vm.SecurityProfile == null) { vm.SecurityProfile = new SecurityProfile(); } vm.SecurityProfile.EncryptionAtHost = this.EncryptionAtHost.IsPresent; } if (this.IsParameterBound(c => c.CapacityReservationGroupId)) { vm.CapacityReservation = new CapacityReservationProfile(); vm.CapacityReservation.CapacityReservationGroup = new SubResource(this.CapacityReservationGroupId); } if (this.IsParameterBound(c => c.UserData)) { if (!ValidateBase64EncodedString.ValidateStringIsBase64Encoded(this.UserData)) { this.UserData = ValidateBase64EncodedString.EncodeStringToBase64(this.UserData); this.WriteInformation(ValidateBase64EncodedString.UserDataEncodeNotification, new string[] { "PSHOST" }); } vm.UserData = this.UserData; } WriteObject(vm); }