diff --git a/src/CLU/CLUCoreCLR.sln b/src/CLU/CLUCoreCLR.sln index ef7c215d2321..bf8dbefe8ea0 100644 --- a/src/CLU/CLUCoreCLR.sln +++ b/src/CLU/CLUCoreCLR.sln @@ -39,6 +39,22 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU", "Microsoft. EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Test", "Microsoft.CLU.Test\Microsoft.CLU.Test.xproj", "{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Compute", "Microsoft.Azure.Commands.Compute\Microsoft.Azure.Commands.Compute.xproj", "{04F9968A-5662-4508-BEE2-31F56848FCBA}" + ProjectSection(ProjectDependencies) = postProject + {99B1290D-A073-4907-8018-51C714431778} = {99B1290D-A073-4907-8018-51C714431778} + {3910613E-4ED2-49E2-8CCF-966D586665AC} = {3910613E-4ED2-49E2-8CCF-966D586665AC} + {81A48E48-89A7-4B93-8207-4F8FA6DC251B} = {81A48E48-89A7-4B93-8207-4F8FA6DC251B} + {45B05B68-516F-4D74-897F-56D12894946C} = {45B05B68-516F-4D74-897F-56D12894946C} + EndProjectSection +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Compute.Test", "Microsoft.Azure.Commands.Compute.Test\Microsoft.Azure.Commands.Compute.Test.xproj", "{13C34370-51A4-4726-81B8-BE0996FC9CFF}" + ProjectSection(ProjectDependencies) = postProject + {3910613E-4ED2-49E2-8CCF-966D586665AC} = {3910613E-4ED2-49E2-8CCF-966D586665AC} + {81A48E48-89A7-4B93-8207-4F8FA6DC251B} = {81A48E48-89A7-4B93-8207-4F8FA6DC251B} + {A9CC2879-D45D-4DCB-A405-6EEDB749B15F} = {A9CC2879-D45D-4DCB-A405-6EEDB749B15F} + {04F9968A-5662-4508-BEE2-31F56848FCBA} = {04F9968A-5662-4508-BEE2-31F56848FCBA} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -117,6 +133,14 @@ Global {91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.Build.0 = Debug|Any CPU {91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.ActiveCfg = Release|Any CPU {91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.Build.0 = Release|Any CPU + {04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {04F9968A-5662-4508-BEE2-31F56848FCBA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {04F9968A-5662-4508-BEE2-31F56848FCBA}.Release|Any CPU.Build.0 = Release|Any CPU + {13C34370-51A4-4726-81B8-BE0996FC9CFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {13C34370-51A4-4726-81B8-BE0996FC9CFF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {13C34370-51A4-4726-81B8-BE0996FC9CFF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {13C34370-51A4-4726-81B8-BE0996FC9CFF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/CLU/Commands.ScenarioTests.ResourceManager.Common/PSCmdletExtensions.cs b/src/CLU/Commands.ScenarioTests.ResourceManager.Common/PSCmdletExtensions.cs index 8c994e4c6092..ea4249296233 100644 --- a/src/CLU/Commands.ScenarioTests.ResourceManager.Common/PSCmdletExtensions.cs +++ b/src/CLU/Commands.ScenarioTests.ResourceManager.Common/PSCmdletExtensions.cs @@ -53,5 +53,11 @@ public static void SetCommandRuntimeMock(this PSCmdlet cmdlet, ICommandRuntime v var property = GetInternalProperty("CommandRuntime", typeof (ICommandRuntime)); property.SetValue(cmdlet, value); } + + public static ICommandRuntime GetCommandRuntimeMock(this PSCmdlet cmdlet) + { + var property = GetInternalProperty("CommandRuntime", typeof(ICommandRuntime)); + return (ICommandRuntime)property.GetValue(cmdlet); + } } } diff --git a/src/CLU/Microsoft.Azure.Commands.Compute.Test/GetAzureVMSizeCommandTests.cs b/src/CLU/Microsoft.Azure.Commands.Compute.Test/GetAzureVMSizeCommandTests.cs new file mode 100644 index 000000000000..0b27ca1bb084 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute.Test/GetAzureVMSizeCommandTests.cs @@ -0,0 +1,137 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute; +using Microsoft.Azure.Commands.ScenarioTest; +using Microsoft.Azure.Commands.Compute.ScenarioTest; +using Microsoft.Azure.Management.Authorization; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using Microsoft.Rest.Azure; +using Moq; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; +using System.Threading; +using System.Threading.Tasks; +using Xunit; +using Microsoft.Azure.Commands.Common.Test.Mocks; +using Microsoft.Azure.Commands.Common.Authentication.Models; +using Microsoft.Azure.Commands.Utilities.Common; + +namespace Microsoft.Azure.Commands.Compute.Test +{ + public class GetAzureVMSizeCommandTests + { + private MemoryDataStore _dataStore; + private MockCommandRuntime _commandRuntimeMock; + + private Mock vmSizesMock; + + public GetAzureVMSizeCommandTests() + { + _dataStore = new MemoryDataStore(); + _commandRuntimeMock = new MockCommandRuntime(); + } + private IPage GetPagableType(List collection) + { + var pagableResult = new Page(); + pagableResult.SetItemValue(collection); + return pagableResult; + } + + private void SetupListForVirtualMachineSizeAsync(string name, List result) + { + vmSizesMock.Setup(f => f.ListWithHttpMessagesAsync(name, null, new CancellationToken())) + .Returns(Task.Factory.StartNew(() => + new AzureOperationResponse> + { + Body = GetPagableType(result) + })); + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void GetVirtualMachineSizesFromLocation() + { + var computeManagementClientMock = new Mock(); + vmSizesMock = new Mock(); + computeManagementClientMock.Setup(f => f.VirtualMachineSizes).Returns(vmSizesMock.Object); + var vmSizeList = new List + { + new VirtualMachineSize + { + Name = "1", + MaxDataDiskCount = 1, + MemoryInMB = 1, + NumberOfCores = 1, + OsDiskSizeInMB = 1, + ResourceDiskSizeInMB = 1 + }, + new VirtualMachineSize + { + Name = "2", + MaxDataDiskCount = 2, + MemoryInMB = 2, + NumberOfCores = 2, + OsDiskSizeInMB = 2, + ResourceDiskSizeInMB = 2 + } + }; + SetupListForVirtualMachineSizeAsync("westus", vmSizeList); + + var progressLoggerMock = new Mock>(); + var errorLoggerMock = new Mock>(); + var computeClient = new ComputeClient(computeManagementClientMock.Object) + { + VerboseLogger = progressLoggerMock.Object, + ErrorLogger = errorLoggerMock.Object + }; + + var profile = new AzureRMProfile(_dataStore); + profile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault()); + profile.Context = new AzureContext(new AzureSubscription(), new AzureAccount(), profile.Environments["foo"]); + GetAzureVMSizeCommand cmdlet = new GetAzureVMSizeCommand + { + ComputeClient = computeClient, + Location = "westus" + }; + cmdlet.DataStore = _dataStore; + cmdlet.SetCommandRuntimeMock(_commandRuntimeMock); + cmdlet.DefaultProfile = profile; + + // Act + cmdlet.InvokeBeginProcessing(); + cmdlet.ExecuteCmdlet(); + cmdlet.InvokeEndProcessing(); + + var runtime = cmdlet.GetCommandRuntimeMock() as MockCommandRuntime; + Assert.True(runtime.OutputPipeline.Count == vmSizeList.Count); + for (int i = 0; i < runtime.OutputPipeline.Count; i++) + { + var item = runtime.OutputPipeline[i] as VirtualMachineSize; + Assert.True(item.Name == vmSizeList[i].Name); + Assert.True(item.MaxDataDiskCount == vmSizeList[i].MaxDataDiskCount); + Assert.True(item.MemoryInMB == vmSizeList[i].MemoryInMB); + Assert.True(item.NumberOfCores == vmSizeList[i].NumberOfCores); + Assert.True(item.OsDiskSizeInMB == vmSizeList[i].OsDiskSizeInMB); + Assert.True(item.ResourceDiskSizeInMB == vmSizeList[i].ResourceDiskSizeInMB); + } + + return; + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute.Test/Microsoft.Azure.Commands.Compute.Test.xproj b/src/CLU/Microsoft.Azure.Commands.Compute.Test/Microsoft.Azure.Commands.Compute.Test.xproj new file mode 100644 index 000000000000..4c678c0971e3 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute.Test/Microsoft.Azure.Commands.Compute.Test.xproj @@ -0,0 +1,21 @@ + + + + 14.0.23107 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 13c34370-51a4-4726-81b8-be0996fc9cff + Microsoft.Azure.Commands.Compute.Test + ..\artifacts\obj\$(MSBuildProjectName) + ..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + + + + \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute.Test/PageExtensions.cs b/src/CLU/Microsoft.Azure.Commands.Compute.Test/PageExtensions.cs new file mode 100644 index 000000000000..8c88b06f4add --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute.Test/PageExtensions.cs @@ -0,0 +1,28 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.Compute.Models; +using System.Collections.Generic; +using System.Reflection; + +namespace Microsoft.Azure.Commands.Compute.ScenarioTest +{ + public static class PageExtensions + { + public static void SetItemValue (this Page pagableObj, List collection) { + var property = typeof(Page).GetProperty("Items", BindingFlags.Instance | BindingFlags.NonPublic); + property.SetValue(pagableObj, collection); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute.Test/project.json b/src/CLU/Microsoft.Azure.Commands.Compute.Test/project.json new file mode 100644 index 000000000000..9be4142b8ff0 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute.Test/project.json @@ -0,0 +1,73 @@ +{ + "version": "1.0.0-*", + "description": "Tests for Compute Resource Provider Cmdlets", + "authors": [ "huangpf", "markcowl", "hovsepm" ], + "tags": [ "" ], + "projectUrl": "", + "licenseUrl": "", + "frameworks": { + "dnxcore50": { + "dependencies": { + "Microsoft.NETCore": "5.0.1-beta-23516", + "Microsoft.NETCore.Platforms": "1.0.1-beta-23516", + "Microsoft.CSharp": "4.0.1-beta-23516" + } + } + }, + "dependencies": { + "AutoMapper": "4.1.1", + "Commands.Common": "", + "Commands.Common.Authentication": "", + "Commands.Common.Storage": "", + "Commands.ResourceManager.Common": "", + "Commands.ResourceManager.Cmdlets": "", + "Commands.ScenarioTests.ResourceManager.Common": "", + "Microsoft.Azure.Commands.Profile": "", + "Microsoft.Azure.Commands.Resources": "", + "Microsoft.Azure.Management.Compute": "11.0.0-prerelease", + "Microsoft.Azure.Management.Network": "3.0.3-preview", + "Microsoft.Azure.Management.Storage": "4.0.0-preview", + "Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha", + "Microsoft.Rest.ClientRuntime": "1.8.0", + "Newtonsoft.Json": "7.0.1", + "System.Collections": "4.0.11-beta-23516", + "System.Collections.Concurrent": "4.0.11-beta-23516", + "System.Diagnostics.Tools": "4.0.1-beta-23516", + "System.Diagnostics.TraceSource": "4.0.0-beta-23516", + "System.Diagnostics.Tracing": "4.0.21-beta-23516", + "System.IO": "4.0.11-beta-23516", + "System.IO.FileSystem": "4.0.1-beta-23516", + "System.Net.Http": "4.0.1-beta-23516", + "System.Net.WebHeaderCollection": "4.0.1-beta-23516", + "System.Reflection": "4.1.0-beta-23516", + "System.Reflection.Extensions": "4.0.1-beta-23516", + "System.Reflection.Primitives": "4.0.1-beta-23516", + "System.Reflection.TypeExtensions": "4.1.0-beta-23516", + "System.Runtime": "4.0.21-beta-23516", + "System.Runtime.Extensions": "4.0.11-beta-23516", + "System.Runtime.Serialization.Json": "4.0.1-beta-23516", + "System.Runtime.Serialization.Primitives": "4.1.0-beta-23516", + "System.Runtime.Serialization.Xml": "4.1.0-beta-23516", + "System.Security.Cryptography.Algorithms": "4.0.0-beta-23516", + "System.Security.Cryptography.X509Certificates": "4.0.0-beta-23516", + "System.Text.Encoding": "4.0.11-beta-23516", + "System.Text.Encoding.Extensions": "4.0.11-beta-23516", + "System.Threading": "4.0.11-beta-23516", + "System.Threading.Tasks": "4.0.11-beta-23516", + "System.Threading.Thread": "4.0.0-beta-23516", + "System.Xml.ReaderWriter": "4.0.11-beta-23516", + "xunit": "2.1.0", + "xunit.assert": "2.1.0", + "xunit.runner.dnx": "2.1.0-rc1-build204", + "moq.netcore": "4.4.0-beta8", + "Microsoft.CLU": "1.0.0", + "System.Linq": "4.0.1-beta-23409", + "System.Xml.XmlDocument": "4.0.1-beta-23516", + "System.Xml.XPath.XmlDocument": "4.0.1-beta-23516", + "WindowsAzure.Storage": "6.1.1-preview", + "Microsoft.Azure.Commands.Compute": "1.0.0-*" + }, + "commands": { + "test": "xunit.runner.dnx" + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/AvailabilitySetBaseCmdlet.cs b/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/AvailabilitySetBaseCmdlet.cs new file mode 100644 index 000000000000..f2758d3f2ccc --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/AvailabilitySetBaseCmdlet.cs @@ -0,0 +1,29 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.Compute; + +namespace Microsoft.Azure.Commands.Compute +{ + public abstract class AvailabilitySetBaseCmdlet : ComputeClientBaseCmdlet + { + public IAvailabilitySetsOperations AvailabilitySetClient + { + get + { + return ComputeClient.ComputeManagementClient.AvailabilitySets; + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/GetAzureAvailabilitySetCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/GetAzureAvailabilitySetCommand.cs new file mode 100644 index 000000000000..25f82da23889 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/GetAzureAvailabilitySetCommand.cs @@ -0,0 +1,72 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using System.Collections.Generic; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, ProfileNouns.AvailabilitySet)] + [OutputType(typeof(PSAvailabilitySet))] + public class GetAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName", "AvailabilitySetName")] + [Parameter( + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The availability set name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (string.IsNullOrEmpty(this.Name)) + { + var result = this.AvailabilitySetClient.List(this.ResourceGroupName); + + List psResultList = new List(); + foreach (var item in result) + { + var psItem = Mapper.Map(item); + psResultList.Add(psItem); + } + + WriteObject(psResultList, true); + } + else + { + var result = this.AvailabilitySetClient.Get(this.ResourceGroupName, this.Name); + var psResult = Mapper.Map(result); + WriteObject(psResult); + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/NewAzureAvailabilitySetCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/NewAzureAvailabilitySetCommand.cs new file mode 100644 index 000000000000..584d436f6a1f --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/NewAzureAvailabilitySetCommand.cs @@ -0,0 +1,88 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.New, ProfileNouns.AvailabilitySet)] + [OutputType(typeof(PSAvailabilitySet))] + public class NewAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName", "AvailabilitySetName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The location.")] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + + [Parameter( + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Platform Update Domain Count.")] + [ValidateNotNullOrEmpty] + public int? PlatformUpdateDomainCount { get; set; } + + [Parameter( + Position = 4, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Platform Fault Domain Count.")] + [ValidateNotNullOrEmpty] + public int? PlatformFaultDomainCount { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + var avSetParams = new AvailabilitySet + { + //Name = this.Name, + Location = this.Location, + PlatformUpdateDomainCount = this.PlatformUpdateDomainCount, + PlatformFaultDomainCount = this.PlatformFaultDomainCount + }; + + var result = this.AvailabilitySetClient.CreateOrUpdate(this.ResourceGroupName, this.Name, avSetParams); + + var psResult = Mapper.Map(result); + WriteObject(psResult); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs new file mode 100644 index 000000000000..392415d25592 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs @@ -0,0 +1,61 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Remove, ProfileNouns.AvailabilitySet)] + [OutputType(typeof(PSOperation))] + public class RemoveAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName", "AvailabilitySetName")] + [Parameter( + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The availability set name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Position = 2, + HelpMessage = "To force the removal.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Force { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (this.Force.IsPresent || this.ShouldContinue("Continue?", "Confirmation")) + { + this.AvailabilitySetClient.Delete(this.ResourceGroupName, this.Name); + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeAutoMapperProfile.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeAutoMapperProfile.cs new file mode 100644 index 000000000000..b49c3954e108 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeAutoMapperProfile.cs @@ -0,0 +1,87 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using System; +using System.Collections; +using System.Collections.Generic; +using FROM = Microsoft.Azure.Management.Compute.Models; +using TO = Microsoft.Azure.Commands.Compute.Models; + +namespace Microsoft.Azure.Commands.Compute +{ + public static class ComputeMapperExtension + { + public static IMappingExpression ForItems( + this IMappingExpression mapper) + where TSource : IEnumerable + where TDestination : ICollection + { + mapper.AfterMap((c, s) => + { + if (c != null && s != null) + { + foreach (var t in c) + { + s.Add(Mapper.Map(t)); + } + } + }); + + return mapper; + } + } + + public class ComputeAutoMapperProfile : AutoMapper.Profile + { + private static readonly Lazy initialize; + + public ComputeAutoMapperProfile() : base("ComputeAutoMapperProfile") + { + } + + static ComputeAutoMapperProfile() + { + initialize = new Lazy(() => + { + Mapper.AddProfile(); + return true; + }); + } + + public static bool Initialize() + { + return initialize.Value; + } + + protected override void Configure() + { + //Mapper.CreateMap(); + Mapper.CreateMap(); + //Mapper.CreateMap(); + + Mapper.CreateMap(); + //Mapper.CreateMap(); + + Mapper.CreateMap(); + //Mapper.CreateMap(); + + Mapper.CreateMap(); + //Mapper.CreateMap(); + + Mapper.CreateMap(); + //Mapper.CreateMap(); + } + } +} \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeClient.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeClient.cs new file mode 100644 index 000000000000..c3ce1e9e2891 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeClient.cs @@ -0,0 +1,40 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Common.Authentication; +using Microsoft.Azure.Commands.Common.Authentication.Models; +using Microsoft.Azure.Management.Compute; +using System; + +namespace Microsoft.Azure.Commands.Compute +{ + public class ComputeClient + { + public IComputeManagementClient ComputeManagementClient { get; private set; } + + public Action VerboseLogger { get; set; } + + public Action ErrorLogger { get; set; } + + public ComputeClient(IClientFactory clientFactory, AzureContext context) + : this(clientFactory.CreateArmClient(context, AzureEnvironment.Endpoint.ResourceManager)) + { + } + + public ComputeClient(IComputeManagementClient computeManagementClient) + { + ComputeManagementClient = computeManagementClient; + } + } +} \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeClientBaseCmdlet.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeClientBaseCmdlet.cs new file mode 100644 index 000000000000..6d2e6439cdcf --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeClientBaseCmdlet.cs @@ -0,0 +1,69 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Rest.Azure; +using Microsoft.WindowsAzure.Commands.Common; +using System; + +namespace Microsoft.Azure.Commands.Compute +{ + public abstract class ComputeClientBaseCmdlet : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + protected const string VirtualMachineExtensionType = "Microsoft.Compute/virtualMachines/extensions"; + + protected override bool IsUsageMetricEnabled + { + get { return true; } + } + + private ComputeClient computeClient; + + public ComputeClient ComputeClient + { + get + { + if (computeClient == null) + { + computeClient = new ComputeClient(ClientFactory, DefaultProfile.Context) + { + VerboseLogger = WriteVerboseWithTimestamp, + ErrorLogger = WriteErrorWithTimestamp + }; + } + + return computeClient; + } + + set { computeClient = value; } + } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + ComputeAutoMapperProfile.Initialize(); + } + + protected void ExecuteClientAction(Action action) + { + try + { + action(); + } + catch (CloudException ex) + { + throw new ComputeCloudException(ex); + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeCloudException.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeCloudException.cs new file mode 100644 index 000000000000..39e71e4052b0 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeCloudException.cs @@ -0,0 +1,60 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Rest.Azure; +using System; +using System.Linq; +using System.Text; + +namespace Microsoft.WindowsAzure.Commands.Common +{ + public class ComputeCloudException : CloudException + { + protected const string RequestIdHeaderInResponse = "x-ms-request-id"; + + public ComputeCloudException(CloudException ex) + : base(GetErrorMessageWithRequestIdInfo(ex), ex) + { + } + + protected static string GetErrorMessageWithRequestIdInfo(CloudException cloudException) + { + if (cloudException == null) + { + throw new ArgumentNullException("cloudException"); + } + + var sb = new StringBuilder(); + + if (!string.IsNullOrEmpty(cloudException.Message)) + { + sb.Append(cloudException.Message); + } + + if (cloudException.Response != null && + cloudException.Response.Headers != null) + { + var headers = cloudException.Response.Headers; + if (headers.Contains(RequestIdHeaderInResponse)) + { + sb.AppendLine().AppendFormat( + "OperationID : '{0}'", + headers.FirstOrDefault(h => string.Equals(h.Key, RequestIdHeaderInResponse))); + } + } + + return sb.ToString(); + } + } +} \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Common/ConstantStringTypes.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Common/ConstantStringTypes.cs new file mode 100644 index 000000000000..2643ed069793 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Common/ConstantStringTypes.cs @@ -0,0 +1,127 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Compute.Common +{ + public static class HelpMessages + { + public const string VMProfile = "The virtual machine profile."; + public const string VMSize = "The virtual machine size."; + public const string VMComputerName = "The virtual machine's omputer name."; + public const string VMCredential = "The virtual machine's credential."; + public const string VMSourceImageName = "The virtual machine's source image name."; + public const string VMImageReference = "The virtual machine's image reference."; + public const string VMVHDContainer = "The virtual machine's Vhd container."; + public const string VMOSDiskName = "The virtual machine OS disk's name."; + public const string VMOSDiskVhdUri = "The virtual machine OS disk's Vhd Uri."; + public const string VMOSDiskCaching = "The virtual machine OS disk's caching."; + public const string VMOSDiskWindowsOSType = "The virtual machine disk's OS is Windows."; + public const string VMOSDiskLinuxOSType = "The virtual machine disk's OS is Linux."; + public const string VMOSDiskDiskEncryptionKeyUrl = "the URL referencing a secret in a disk encryption key vault"; + public const string VMOSDiskDiskEncryptionKeyVaultId = "the Id of a disk encryption key vault"; + public const string VMOSDiskKeyEncryptionKeyUrl = "the URL referencing a key in a key encryption key vault"; + public const string VMOSDiskKeyEncryptionKeyVaultId = "the Id of a key encryption key Vault"; + public const string VMSourceImageUri = "The virtual machine OS disk's source image Uri."; + + public const string VMDataDiskName = "The virtual machine data disk's name."; + public const string VMDataDiskVhdUri = "The virtual machine data disk's Vhd Uri."; + public const string VMDataDiskCaching = "The virtual machine data disk's caching."; + public const string VMDataDiskSizeInGB = "The virtual machine data disk's size in GB."; + public const string VMDataDiskLun = "The virtual machine data disk's Lun."; + public const string VMDataDiskCreateOption = "The virtual machine data disk's create option."; + + public const string VMNetworkInterfaceName = "The virtual machine network interface's name."; + public const string VMNetworkInterfaceID = "The virtual machine network interface's ID."; + public const string VMPublicIPAddressName = "The virtual machine public IP address's name."; + public const string VMPublicIPAddressReferenceUri = "The virtual machine public IP address's reference Uri."; + + public const string VMBootDiagnosticsEnable = "Enable boot diagnostics data of the virtual machine"; + public const string VMBootDiagnosticsDisable = "Disable boot diagnostics data of the virtual machine"; + public const string VMBootDiagnosticsResourceGroupName = "Resource group name for storage account"; + public const string VMBootDiagnosticsStorageAccountName = "Storage account name for boot diagnostics data"; + } + + public static class ValidateSetValues + { + public const string ReadOnly = "ReadOnly"; + public const string ReadWrite = "ReadWrite"; + public const string None = "None"; + } + + public static class ProfileNouns + { + public const string VirtualMachineProfile = "AzureRmVMProfile"; + + public const string OSProfile = "AzureRmVMOSProfile"; + public const string StorageProfile = "AzureRmVMStorageProfile"; + public const string HardwareProfile = "AzureRmVMHardwareProfile"; + public const string NetworkProfile = "AzureRmVMNetworkProfile"; + + public const string OperatingSystem = "AzureRmVMOperatingSystem"; + + public const string DataDisk = "AzureRmVMDataDisk"; + public const string OSDisk = "AzureRmVMOSDisk"; + public const string SourceImage = "AzureRmVMSourceImage"; + public const string BootDiagnostics = "AzureRmVMBootDiagnostics"; + public const string BootDiagnosticsData = "AzureRmVMBootDiagnosticsData"; + + public const string NetworkInterface = "AzureRmVMNetworkInterface"; + + public const string VirtualMachine = "AzureRmVM"; + public const string VirtualMachineExtension = "AzureRmVMExtension"; + public const string VirtualMachineCustomScriptExtension = "AzureRmVMCustomScriptExtension"; + public const string VirtualMachineAccessExtension = "AzureRmVMAccessExtension"; + public const string VirtualMachineDiagnosticsExtension = "AzureRmVMDiagnosticsExtension"; + public const string VirtualMachineExtensionImage = "AzureRmVmExtensionImage"; + public const string VirtualMachineExtensionImageVersion = "AzureRmVMExtensionImageVersion"; + public const string VirtualMachineExtensionImageType = "AzureRmVMExtensionImageType"; + + public const string AvailabilitySet = "AzureRmAvailabilitySet"; + public const string VirtualMachineConfig = "AzureRmVMConfig"; + public const string VirtualMachinePlan = "AzureRmVMPlan"; + + public const string VirtualMachineSize = "AzureRmVMSize"; + + public const string VirtualMachineImage = "AzureRmVMImage"; + public const string VirtualMachineImagePublisher = "AzureRmVMImagePublisher"; + public const string VirtualMachineImageOffer = "AzureRmVMImageOffer"; + public const string VirtualMachineImageSku = "AzureRmVMImageSku"; + public const string VirtualMachineImageVersion = "AzureRmVMImageVersion"; + + public const string VirtualMachineUsage = "AzureRmVMUsage"; + + public const string SshPublicKey = "AzureRmVMSshPublicKey"; + public const string AdditionalUnattendContent = "AzureRmVMAdditionalUnattendContent"; + public const string VaultSecretGroup = "AzureRmVMSecret"; + public const string RemoteDesktopFile = "AzureRmRemoteDesktopFile"; + + //DSC + public const string VirtualMachineDscExtension = "AzureRmVMDscExtension"; + public const string VirtualMachineDscConfiguration = "AzureRmVMDscConfiguration"; + public const string VirtualMachineDscExtensionStatus = "AzureRmVMDscExtensionStatus"; + public const string Vhd = "AzureRmVhd"; + + // Sql Server + public const string VirtualMachineSqlServerExtension = "AzureRmVMSqlServerExtension"; + + //AzureDiskEncryption + public const string AzureDiskEncryptionExtension = "AzureRmVMDiskEncryptionExtension"; + public const string AzureDiskEncryptionStatus = "AzureRmVMDiskEncryptionStatus"; + + //AzureVMBackup + public const string AzureVMBackup = "AzureRmVMBackup"; + public const string AzureVMBackupExtension = "AzureRmVMBackupExtension"; + + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Common/DiagnosticsHelper.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Common/DiagnosticsHelper.cs new file mode 100644 index 000000000000..167234df0ed6 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Common/DiagnosticsHelper.cs @@ -0,0 +1,125 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections; +using System.IO; +using System.Text; +using System.Xml; +using Newtonsoft.Json; + +namespace Microsoft.WindowsAzure.Commands.Utilities.Common +{ + public static class DiagnosticsHelper + { + private static string XmlNamespace = "http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration"; + private static string EncodedXmlCfg = "xmlCfg"; + private static string StorageAccount = "storageAccount"; + private static string Path = "path"; + private static string ExpandResourceDirectory = "expandResourceDirectory"; + private static string LocalResourceDirectory = "localResourceDirectory"; + private static string StorageAccountNameTag = "storageAccountName"; + private static string StorageAccountKeyTag = "storageAccountKey"; + private static string StorageAccountEndPointTag = "storageAccountEndPoint"; + + public static string GetJsonSerializedPublicDiagnosticsConfigurationFromFile(string configurationPath, + string storageAccountName) + { + return + JsonConvert.SerializeObject( + DiagnosticsHelper.GetPublicDiagnosticsConfigurationFromFile(configurationPath, storageAccountName)); + } + + public static Hashtable GetPublicDiagnosticsConfigurationFromFile(string configurationPath, string storageAccountName) + { + using (StreamReader reader = new StreamReader(File.OpenRead(configurationPath))) + { + return GetPublicDiagnosticsConfiguration(reader.ReadToEnd(), storageAccountName); + } + } + + public static Hashtable GetPublicDiagnosticsConfiguration(string config, string storageAccountName) + { + // find the element and extract it + int wadCfgBeginIndex = config.IndexOf(""); + if (wadCfgBeginIndex == -1) + { + throw new ArgumentException("Cannot find the WadCfg element in the config."); + } + + int wadCfgEndIndex = config.IndexOf(""); + if (wadCfgEndIndex == -1) + { + throw new ArgumentException("Cannot find the WadCfg end element in the config."); + } + + if (wadCfgEndIndex <= wadCfgBeginIndex) + { + throw new ArgumentException("WadCfg start element in the config is not matching the end element."); + } + + string encodedConfiguration = Convert.ToBase64String( + Encoding.UTF8.GetBytes( + config.Substring( + wadCfgBeginIndex, wadCfgEndIndex + "".Length - wadCfgBeginIndex).ToCharArray())); + + // Now extract the local resource directory element + XmlDocument doc = new XmlDocument(); + XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); + ns.AddNamespace("ns", XmlNamespace); + doc.LoadXml(config); + XmlNode node = doc.SelectSingleNode("//ns:LocalResourceDirectory", ns); + string localDirectory = (node != null && node.Attributes != null) ? node.Attributes[Path].Value : null; + string localDirectoryExpand = (node != null && node.Attributes != null) + ? node.Attributes["expandEnvironment"].Value + : null; + if (localDirectoryExpand == "0") + { + localDirectoryExpand = "false"; + } + if (localDirectoryExpand == "1") + { + localDirectoryExpand = "true"; + } + + var hashTable = new Hashtable(); + hashTable.Add(EncodedXmlCfg, encodedConfiguration); + hashTable.Add(StorageAccount, storageAccountName); + if (!string.IsNullOrEmpty(localDirectory)) + { + var localDirectoryHashTable = new Hashtable(); + localDirectoryHashTable.Add(Path, localDirectory); + localDirectoryHashTable.Add(ExpandResourceDirectory, localDirectoryExpand); + hashTable.Add(LocalResourceDirectory, localDirectoryHashTable); + } + + return hashTable; + } + + public static string GetJsonSerializedPrivateDiagnosticsConfiguration(string storageAccountName, + string storageKey, string endpoint) + { + return JsonConvert.SerializeObject(GetPrivateDiagnosticsConfiguration( storageAccountName, storageKey, endpoint)); + } + + public static Hashtable GetPrivateDiagnosticsConfiguration(string storageAccountName, string storageKey, string endpoint) + { + var hashTable = new Hashtable(); + hashTable.Add(StorageAccountNameTag, storageAccountName); + hashTable.Add(StorageAccountKeyTag, storageKey); + hashTable.Add(StorageAccountEndPointTag, endpoint); + return hashTable; + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Common/HashTableExtensions.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Common/HashTableExtensions.cs new file mode 100644 index 000000000000..0e42528425ec --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Common/HashTableExtensions.cs @@ -0,0 +1,28 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Tags.Model; +using System.Collections; +using System.Collections.Generic; + +namespace Microsoft.Azure.Commands.Compute.Common +{ + public static class HashTableExtensions + { + public static Dictionary ToDictionary(this Hashtable[] tags) + { + return TagsConversionHelper.CreateTagDictionary(tags, true); + } + } +} \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Common/LocationStringExtensions.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Common/LocationStringExtensions.cs new file mode 100644 index 000000000000..98b24f8a9ab4 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Common/LocationStringExtensions.cs @@ -0,0 +1,40 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Text; + +namespace Microsoft.Azure.Commands.Compute.Common +{ + public static class LocationStringExtensions + { + public static string Canonicalize(this string location) + { + if (!string.IsNullOrEmpty(location)) + { + StringBuilder sb = new StringBuilder(); + foreach (char ch in location) + { + if (!char.IsWhiteSpace(ch)) + { + sb.Append(ch); + } + } + + location = sb.ToString().ToLower(); + } + + return location; + } + } +} \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Content/azure.lx b/src/CLU/Microsoft.Azure.Commands.Compute/Content/azure.lx new file mode 100644 index 000000000000..8ab6450921c3 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Content/azure.lx @@ -0,0 +1,5 @@ +RtPackage: Microsoft.CLU.Commands +RtEntry: Microsoft.CLU.CommandModel.CmdletCommandModel.Run +RtAssembly: Microsoft.CLU.dll +Modules: Microsoft.Azure.Commands.Compute +NounPrefix: AzureRm \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Content/package.cfg b/src/CLU/Microsoft.Azure.Commands.Compute/Content/package.cfg new file mode 100644 index 000000000000..7c4977ed6459 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Content/package.cfg @@ -0,0 +1,4 @@ +Name: Microsoft.Azure.Commands.Compute +CommandAssemblies: Microsoft.Azure.Commands.Compute.dll +NounPrefix: AzureRm +NounFirst: true \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/EntryStub.cs b/src/CLU/Microsoft.Azure.Commands.Compute/EntryStub.cs new file mode 100644 index 000000000000..9c5c6cbb3a51 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/EntryStub.cs @@ -0,0 +1,24 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Compute +{ + public class EntryStub + { + public static void Main(string[] args) + { + // empty entry point + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/CustomScriptExtensionPrivateSettings.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/CustomScriptExtensionPrivateSettings.cs new file mode 100644 index 000000000000..e3357cfba17f --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/CustomScriptExtensionPrivateSettings.cs @@ -0,0 +1,22 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Compute +{ + public class CustomScriptExtensionPrivateSettings + { + public string storageAccountName; + public string storageAccountKey; + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/CustomScriptExtensionPublicSettings.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/CustomScriptExtensionPublicSettings.cs new file mode 100644 index 000000000000..f24ab7e08c90 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/CustomScriptExtensionPublicSettings.cs @@ -0,0 +1,22 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Compute +{ + public class CustomScriptExtensionPublicSettings + { + public string[] fileUris; + public string commandToExecute; + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/GetAzureVMCustomScriptExtensionCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/GetAzureVMCustomScriptExtensionCommand.cs new file mode 100644 index 000000000000..c8fce7a52338 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/GetAzureVMCustomScriptExtensionCommand.cs @@ -0,0 +1,106 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Newtonsoft.Json; +using System; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Get, + ProfileNouns.VirtualMachineCustomScriptExtension, + DefaultParameterSetName = GetCustomScriptExtensionParamSetName), + OutputType( + typeof(VirtualMachineCustomScriptExtensionContext))] + public class GetAzureVMCustomScriptExtensionCommand : VirtualMachineExtensionBaseCmdlet + { + protected const string GetCustomScriptExtensionParamSetName = "GetCustomScriptExtension"; + + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string VMName { get; set; } + + [Alias("ExtensionName")] + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The extension name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = "To show the status.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Status { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (Status) + { + var result = this.VirtualMachineExtensionClient.Get(this.ResourceGroupName, this.VMName, this.Name, "instanceView"); + var returnedExtension = result.ToPSVirtualMachineExtension(this.ResourceGroupName); + + if (returnedExtension.Publisher.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultPublisher, StringComparison.OrdinalIgnoreCase) && + returnedExtension.ExtensionType.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultName, StringComparison.OrdinalIgnoreCase)) + { + WriteObject(new VirtualMachineCustomScriptExtensionContext(returnedExtension)); + } + else + { + WriteObject(null); + } + } + else + { + var result = this.VirtualMachineExtensionClient.Get(this.ResourceGroupName, this.VMName, this.Name); + var returnedExtension = result.ToPSVirtualMachineExtension(this.ResourceGroupName); + + if (returnedExtension.Publisher.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultPublisher, StringComparison.OrdinalIgnoreCase) && + returnedExtension.ExtensionType.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultName, StringComparison.OrdinalIgnoreCase)) + { + WriteObject(new VirtualMachineCustomScriptExtensionContext(returnedExtension)); + } + else + { + WriteObject(null); + } + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/RemoveAzureVMCustomScriptExtensionCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/RemoveAzureVMCustomScriptExtensionCommand.cs new file mode 100644 index 000000000000..eceb0d99f227 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/RemoveAzureVMCustomScriptExtensionCommand.cs @@ -0,0 +1,70 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Management.Compute; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Remove, + ProfileNouns.VirtualMachineCustomScriptExtension)] + public class RemoveAzureVMCustomScriptExtensionCommand : VirtualMachineExtensionBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string VMName { get; set; } + + [Alias("ExtensionName")] + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The extension name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter(HelpMessage = "To force the removal.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Force { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalConfirmation"), Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalCaption"))) + { + this.VirtualMachineExtensionClient.Delete(this.ResourceGroupName, this.VMName, this.Name); + } + }); + } + + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/SetAzureVMCustomScriptExtensionCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/SetAzureVMCustomScriptExtensionCommand.cs new file mode 100644 index 000000000000..851748e3bcb4 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/SetAzureVMCustomScriptExtensionCommand.cs @@ -0,0 +1,303 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using Microsoft.Azure.Management.Storage; +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Auth; +using Microsoft.WindowsAzure.Storage.Blob; +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Management.Automation; +using System.Linq; +using Microsoft.Azure.Commands.Common.Authentication.Models; +using Microsoft.Azure.Commands.Common.Authentication; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Set, + ProfileNouns.VirtualMachineCustomScriptExtension, + DefaultParameterSetName = SetCustomScriptExtensionByContainerBlobsParamSetName)] + public class SetAzureVMCustomScriptExtensionCommand : VirtualMachineExtensionBaseCmdlet + { + protected const string SetCustomScriptExtensionByContainerBlobsParamSetName = "SetCustomScriptExtensionByContainerAndFileNames"; + protected const string SetCustomScriptExtensionByUrisParamSetName = "SetCustomScriptExtensionByUriLinks"; + + private const string fileUrisKey = "fileUris"; + private const string commandToExecuteKey = "commandToExecute"; + private const string storageAccountNameKey = "storageAccountName"; + private const string storageAccountKeyKey = "storageAccountKey"; + + + private const string poshCmdFormatStr = "powershell {0} -file {1} {2}"; + private const string defaultPolicyStr = "Unrestricted"; + private const string policyFormatStr = "-ExecutionPolicy {0}"; + + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string VMName { get; set; } + + [Alias("ExtensionName")] + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The extension name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Alias("HandlerVersion", "Version")] + [Parameter( + Mandatory = false, + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The type handler version.")] + [ValidateNotNullOrEmpty] + public string TypeHandlerVersion { get; set; } + + [Parameter( + ParameterSetName = SetCustomScriptExtensionByContainerBlobsParamSetName, + Mandatory = true, + Position = 4, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Name of the Container.")] + [ValidateNotNullOrEmpty] + public string ContainerName { get; set; } + + [Parameter( + ParameterSetName = SetCustomScriptExtensionByContainerBlobsParamSetName, + Mandatory = true, + Position = 5, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Blob Files in the Container.")] + [ValidateNotNullOrEmpty] + public string[] FileName { get; set; } + + [Parameter( + ParameterSetName = SetCustomScriptExtensionByContainerBlobsParamSetName, + Mandatory = false, + Position = 6, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Storage Account Name.")] + [ValidateNotNullOrEmpty] + public string StorageAccountName { get; set; } + + [Parameter( + ParameterSetName = SetCustomScriptExtensionByContainerBlobsParamSetName, + Mandatory = false, + Position = 7, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Storage Endpoint Suffix.")] + [ValidateNotNullOrEmpty] + public string StorageEndpointSuffix { get; set; } + + [Parameter( + ParameterSetName = SetCustomScriptExtensionByContainerBlobsParamSetName, + Mandatory = false, + Position = 8, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Storage Account Key.")] + [ValidateNotNullOrEmpty] + public string StorageAccountKey { get; set; } + + [Parameter( + ParameterSetName = SetCustomScriptExtensionByUrisParamSetName, + Mandatory = false, + Position = 4, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The File URIs.")] + [ValidateNotNullOrEmpty] + public string[] FileUri { get; set; } + + [Parameter( + ParameterSetName = SetCustomScriptExtensionByContainerBlobsParamSetName, + Mandatory = false, + Position = 9, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Run File to Execute in PowerShell on the VM.")] + [Parameter( + ParameterSetName = SetCustomScriptExtensionByUrisParamSetName, + Mandatory = true, + Position = 5, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Run File to Execute in PowerShell on the VM.")] + [ValidateNotNullOrEmpty] + [Alias("RunFile", "Command")] + public string Run { get; set; } + + [Parameter( + ParameterSetName = SetCustomScriptExtensionByContainerBlobsParamSetName, + Mandatory = false, + Position = 10, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Argument String for the Run File.")] + [Parameter( + ParameterSetName = SetCustomScriptExtensionByUrisParamSetName, + Mandatory = false, + Position = 6, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Argument String for the Run File.")] + [ValidateNotNullOrEmpty] + public string Argument { get; set; } + + [Parameter( + Position = 11, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The location.")] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (string.Equals(this.ParameterSetName, SetCustomScriptExtensionByContainerBlobsParamSetName)) + { + this.StorageEndpointSuffix = string.IsNullOrEmpty(this.StorageEndpointSuffix) ? + DefaultProfile.Context.Environment.GetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix) : this.StorageEndpointSuffix; + var sName = string.IsNullOrEmpty(this.StorageAccountName) ? GetStorageName() : this.StorageAccountName; + var sKey = string.IsNullOrEmpty(this.StorageAccountKey) ? GetStorageKey(sName) : this.StorageAccountKey; + + if (this.FileName != null && this.FileName.Any()) + { + this.FileUri = (from blobName in this.FileName + select GetSasUrlStr(sName, sKey, this.ContainerName, blobName)).ToArray(); + + if (string.IsNullOrEmpty(this.Run)) + { + WriteWarning(Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("CustomScriptExtensionTryToUseTheFirstSpecifiedFileAsRunScript")); + this.Run = this.FileName[0]; + } + } + } + + var policyStr = string.Format(policyFormatStr, defaultPolicyStr); + var commandToExecute = string.Format(poshCmdFormatStr, policyStr, this.Run, this.Argument); + + Hashtable publicSettings = new Hashtable(); + publicSettings.Add(commandToExecuteKey, commandToExecute ?? ""); + publicSettings.Add(fileUrisKey, FileUri ?? new string[] { }); + var SettingString = JsonConvert.SerializeObject(publicSettings); + + var parameters = new VirtualMachineExtension + { + Location = this.Location, + Publisher = VirtualMachineCustomScriptExtensionContext.ExtensionDefaultPublisher, + VirtualMachineExtensionType = VirtualMachineCustomScriptExtensionContext.ExtensionDefaultName, + TypeHandlerVersion = (this.TypeHandlerVersion) ?? VirtualMachineCustomScriptExtensionContext.ExtensionDefaultVersion, + Settings = SettingString, + ProtectedSettings = GetPrivateConfiguration(), + }; + + var op = this.VirtualMachineExtensionClient.CreateOrUpdate( + this.ResourceGroupName, + this.VMName, + this.Name, + parameters); + + WriteObject(op); + }); + } + + protected string GetStorageName() + { + return DefaultProfile.Context.Subscription.GetProperty(AzureSubscription.Property.StorageAccount); + } + + protected string GetStorageKey(string storageName) + { + string storageKey = string.Empty; + + if (!string.IsNullOrEmpty(storageName)) + { + var storageClient = ClientFactory.CreateArmClient(DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager); + + var storageAccount = storageClient.StorageAccounts.GetProperties(this.ResourceGroupName, storageName); + + if (storageAccount != null) + { + var keys = storageClient.StorageAccounts.ListKeys(this.ResourceGroupName, storageName); + if (keys != null) + { + storageKey = !string.IsNullOrEmpty(keys.Key1) ? keys.Key1 : keys.Key2; + } + } + } + + return storageKey; + } + + protected string GetSasUrlStr(string storageName, string storageKey, string containerName, string blobName) + { + var storageClient = ClientFactory.CreateArmClient(DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager); + var cred = new StorageCredentials(storageName, storageKey); + var storageAccount = string.IsNullOrEmpty(this.StorageEndpointSuffix) + ? new CloudStorageAccount(cred, true) + : new CloudStorageAccount(cred, this.StorageEndpointSuffix, true); + + var blobClient = storageAccount.CreateCloudBlobClient(); + var container = blobClient.GetContainerReference(containerName); + var cloudBlob = container.GetBlockBlobReference(blobName); + var sasToken = cloudBlob.GetSharedAccessSignature( + new SharedAccessBlobPolicy() + { + SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24.0), + Permissions = SharedAccessBlobPermissions.Read + }); + + // Try not to use a Uri object in order to keep the following + // special characters in the SAS signature section: + // '+' -> '%2B' + // '/' -> '%2F' + // '=' -> '%3D' + return cloudBlob.Uri + sasToken; + } + + protected string GetPrivateConfiguration() + { + if (string.IsNullOrEmpty(this.StorageAccountName) || string.IsNullOrEmpty(this.StorageAccountKey)) + { + return null; + } + else + { + var privateSettings = new Hashtable(); + privateSettings.Add(storageAccountNameKey, StorageAccountName); + privateSettings.Add(storageAccountKeyKey, StorageAccountKey); + return JsonUtilities.TryFormatJson(JsonConvert.SerializeObject(privateSettings)); + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/VirtualMachineCustomScriptExtensionContext.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/VirtualMachineCustomScriptExtensionContext.cs new file mode 100644 index 000000000000..a6b142496e36 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/VirtualMachineCustomScriptExtensionContext.cs @@ -0,0 +1,50 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Newtonsoft.Json; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class VirtualMachineCustomScriptExtensionContext : PSVirtualMachineExtension + { + public const string ExtensionDefaultPublisher = "Microsoft.Compute"; + public const string ExtensionDefaultName = "CustomScriptExtension"; + public const string ExtensionDefaultVersion = "1.4"; + + + public string CommandToExecute { get; set; } + public string[] Uri { get; set; } + + public VirtualMachineCustomScriptExtensionContext(PSVirtualMachineExtension psExt) + { + var publicSettings = string.IsNullOrEmpty(psExt.PublicSettings) ? null + : JsonConvert.DeserializeObject(psExt.PublicSettings); + + ResourceGroupName = psExt.ResourceGroupName; + Name = psExt.Name; + Location = psExt.Location; + Etag = psExt.Etag; + Publisher = psExt.Publisher; + ExtensionType = psExt.ExtensionType; + TypeHandlerVersion = psExt.TypeHandlerVersion; + Id = psExt.Id; + PublicSettings = psExt.PublicSettings; + ProtectedSettings = psExt.ProtectedSettings; + ProvisioningState = psExt.ProvisioningState; + Statuses = psExt.Statuses; + CommandToExecute = (publicSettings == null) ? null : publicSettings.commandToExecute; + Uri = (publicSettings == null) ? null : publicSettings.fileUris; + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/GetAzureVMExtensionCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/GetAzureVMExtensionCommand.cs new file mode 100644 index 000000000000..27b97059d992 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/GetAzureVMExtensionCommand.cs @@ -0,0 +1,78 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineExtension)] + [OutputType(typeof(PSVirtualMachineExtension))] + public class GetAzureVMExtensionCommand : VirtualMachineExtensionBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string VMName { get; set; } + + [Alias("ExtensionName")] + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The extension name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = "To show the status.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Status { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (Status.IsPresent) + { + var result = this.VirtualMachineExtensionClient.Get(this.ResourceGroupName, this.VMName, this.Name, "instanceView"); + WriteObject(result.ToPSVirtualMachineExtension(this.ResourceGroupName)); + } + else + { + var result = this.VirtualMachineExtensionClient.Get(this.ResourceGroupName, this.VMName, this.Name); + WriteObject(result.ToPSVirtualMachineExtension(this.ResourceGroupName)); + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/RemoveAzureVMExtensionCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/RemoveAzureVMExtensionCommand.cs new file mode 100644 index 000000000000..9cfa8c0d2419 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/RemoveAzureVMExtensionCommand.cs @@ -0,0 +1,70 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Remove, ProfileNouns.VirtualMachineExtension)] + [OutputType(typeof(PSComputeLongRunningOperation))] + public class RemoveAzureVMExtensionCommand : VirtualMachineExtensionBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string VMName { get; set; } + + [Alias("ExtensionName")] + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The extension name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter(HelpMessage = "To force the removal.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Force { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalConfirmation"), Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalCaption"))) + { + this.VirtualMachineExtensionClient.Delete(this.ResourceGroupName, this.VMName, this.Name); + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/SetAzureVMExtensionCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/SetAzureVMExtensionCommand.cs new file mode 100644 index 000000000000..fc7fe24a30cb --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/SetAzureVMExtensionCommand.cs @@ -0,0 +1,159 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using Newtonsoft.Json; +using System.Collections; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Set, + ProfileNouns.VirtualMachineExtension, + DefaultParameterSetName = SettingsParamSet)] + [OutputType(typeof(PSComputeLongRunningOperation))] + public class SetAzureVMExtensionCommand : VirtualMachineExtensionBaseCmdlet + { + protected const string SettingStringParamSet = "SettingString"; + protected const string SettingsParamSet = "Settings"; + + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string VMName { get; set; } + + [Alias("ExtensionName")] + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The extension name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Mandatory = true, + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The publisher.")] + [ValidateNotNullOrEmpty] + public string Publisher { get; set; } + + [Parameter( + Mandatory = true, + Position = 4, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The type.")] + [ValidateNotNullOrEmpty] + public string ExtensionType { get; set; } + + [Alias("HandlerVersion", "Version")] + [Parameter( + Mandatory = true, + Position = 5, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The type.")] + [ValidateNotNullOrEmpty] + public string TypeHandlerVersion { get; set; } + + [Parameter( + ParameterSetName = SettingsParamSet, + Position = 6, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The settings.")] + [ValidateNotNullOrEmpty] + public Hashtable Settings { get; set; } + + [Parameter( + ParameterSetName = SettingsParamSet, + Position = 7, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The protected settings.")] + [ValidateNotNullOrEmpty] + public Hashtable ProtectedSettings { get; set; } + + [Parameter( + ParameterSetName = SettingStringParamSet, + Position = 6, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The setting raw string.")] + [ValidateNotNullOrEmpty] + public string SettingString { get; set; } + + [Parameter( + ParameterSetName = SettingStringParamSet, + Position = 7, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The protected setting raw string.")] + [ValidateNotNullOrEmpty] + public string ProtectedSettingString { get; set; } + + [Parameter( + Position = 8, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The location.")] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (this.Settings != null) + { + this.SettingString = JsonConvert.SerializeObject(Settings); + this.ProtectedSettingString = JsonConvert.SerializeObject(ProtectedSettings); + } + + var parameters = new VirtualMachineExtension + { + Location = this.Location, + Publisher = this.Publisher, + VirtualMachineExtensionType = this.ExtensionType, + TypeHandlerVersion = this.TypeHandlerVersion, + Settings = this.SettingString, + ProtectedSettings = this.ProtectedSettingString, + }; + + var op = this.VirtualMachineExtensionClient.CreateOrUpdate( + this.ResourceGroupName, + this.VMName, + this.Name, + parameters); + + var result = Mapper.Map(op); + WriteObject(result); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/GetAzureVMAccessExtension.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/GetAzureVMAccessExtension.cs new file mode 100644 index 000000000000..9891fe276279 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/GetAzureVMAccessExtension.cs @@ -0,0 +1,104 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Newtonsoft.Json; +using System; +using System.Linq; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Get, + ProfileNouns.VirtualMachineAccessExtension), + OutputType(typeof(VirtualMachineAccessExtensionContext))] + public class GetAzureVMAccessExtensionCommand : VirtualMachineExtensionBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string VMName { get; set; } + + [Alias("ExtensionName")] + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The extension name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = "To show the status.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Status { get; set; } + + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (Status.IsPresent) + { + var result = this.VirtualMachineExtensionClient.Get(this.ResourceGroupName, this.VMName, this.Name, "instanceView"); + var returnedExtension = result.ToPSVirtualMachineExtension(this.ResourceGroupName); + + if (returnedExtension.Publisher.Equals(VirtualMachineAccessExtensionContext.ExtensionDefaultPublisher, StringComparison.OrdinalIgnoreCase) && + returnedExtension.ExtensionType.Equals(VirtualMachineAccessExtensionContext.ExtensionDefaultName, StringComparison.OrdinalIgnoreCase)) + { + WriteObject(new VirtualMachineAccessExtensionContext(returnedExtension)); + } + else + { + WriteObject(null); + } + } + else + { + var result = this.VirtualMachineExtensionClient.Get(this.ResourceGroupName, this.VMName, this.Name); + var returnedExtension = result.ToPSVirtualMachineExtension(this.ResourceGroupName); + + if (returnedExtension.Publisher.Equals(VirtualMachineAccessExtensionContext.ExtensionDefaultPublisher, StringComparison.OrdinalIgnoreCase) && + returnedExtension.ExtensionType.Equals(VirtualMachineAccessExtensionContext.ExtensionDefaultName, StringComparison.OrdinalIgnoreCase)) + { + WriteObject(new VirtualMachineAccessExtensionContext(returnedExtension)); + } + else + { + WriteObject(null); + } + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/RemoveAzureVMAccessExtension.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/RemoveAzureVMAccessExtension.cs new file mode 100644 index 000000000000..87ed45282dc4 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/RemoveAzureVMAccessExtension.cs @@ -0,0 +1,69 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Management.Compute; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Remove, + ProfileNouns.VirtualMachineAccessExtension)] + public class RemoveAzureVMAccessExtensionCommand : VirtualMachineExtensionBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string VMName { get; set; } + + [Alias("ExtensionName")] + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The extension name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter(HelpMessage = "To force the removal.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Force { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalConfirmation"), Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalCaption"))) + { + this.VirtualMachineExtensionClient.Delete(this.ResourceGroupName, this.VMName, this.Name); + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/SetAzureVMAccessExtension.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/SetAzureVMAccessExtension.cs new file mode 100644 index 000000000000..fc7149a06210 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/SetAzureVMAccessExtension.cs @@ -0,0 +1,124 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using Newtonsoft.Json; +using System.Collections; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Set, + ProfileNouns.VirtualMachineAccessExtension)] + public class SetAzureVMAccessExtensionCommand : VirtualMachineExtensionBaseCmdlet + { + private const string userNameKey = "UserName"; + private const string passwordKey = "Password"; + + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string VMName { get; set; } + + [Alias("ExtensionName")] + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The extension name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Alias("HandlerVersion", "Version")] + [Parameter( + Mandatory = false, + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The type handler version.")] + [ValidateNotNullOrEmpty] + public string TypeHandlerVersion { get; set; } + + [Parameter( + Mandatory = false, + Position = 4, + ValueFromPipelineByPropertyName = true, + HelpMessage = "New or Existing User Name")] + public string UserName { get; set; } + + [Parameter( + Mandatory = false, + Position = 5, + ValueFromPipelineByPropertyName = true, + HelpMessage = "New or Existing User Password")] + public string Password { get; set; } + + [Parameter( + Position = 6, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The location.")] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + Hashtable publicSettings = new Hashtable(); + publicSettings.Add(userNameKey, UserName ?? ""); + + Hashtable privateSettings = new Hashtable(); + privateSettings.Add(passwordKey, Password ?? ""); + + var SettingString = JsonConvert.SerializeObject(publicSettings); + var ProtectedSettingString = JsonConvert.SerializeObject(privateSettings); + + var parameters = new VirtualMachineExtension + { + Location = this.Location, + Publisher = VirtualMachineAccessExtensionContext.ExtensionDefaultPublisher, + VirtualMachineExtensionType = VirtualMachineAccessExtensionContext.ExtensionDefaultName, + TypeHandlerVersion = (this.TypeHandlerVersion) ?? VirtualMachineAccessExtensionContext.ExtensionDefaultVersion, + Settings = SettingString, + ProtectedSettings = ProtectedSettingString, + }; + + var op = this.VirtualMachineExtensionClient.CreateOrUpdate( + this.ResourceGroupName, + this.VMName, + this.Name, + parameters); + + WriteObject(op); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/VMAccessExtensionPrivateSettings.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/VMAccessExtensionPrivateSettings.cs new file mode 100644 index 000000000000..3b521aa2798e --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/VMAccessExtensionPrivateSettings.cs @@ -0,0 +1,21 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Compute +{ + public class VMAccessExtensionPrivateSettings + { + public string Password; + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/VMAccessExtensionPublicSettings.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/VMAccessExtensionPublicSettings.cs new file mode 100644 index 000000000000..57288590c8c2 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/VMAccessExtensionPublicSettings.cs @@ -0,0 +1,21 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Compute +{ + public class VMAccessExtensionPublicSettings + { + public string UserName; + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/VirtualMachineAccessExtensionContext.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/VirtualMachineAccessExtensionContext.cs new file mode 100644 index 000000000000..1005bf13cea2 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/VirtualMachineAccessExtensionContext.cs @@ -0,0 +1,51 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +//using Microsoft.Azure.Commands.Compute.Models; +using Newtonsoft.Json; +using System.Security; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class VirtualMachineAccessExtensionContext : PSVirtualMachineExtension + { + + public const string ExtensionDefaultPublisher = "Microsoft.Compute"; + public const string ExtensionDefaultName = "VMAccessAgent"; + public const string ExtensionDefaultVersion = "2.0"; + + public string UserName { get; set; } + public string Password { get; set; } + + public VirtualMachineAccessExtensionContext(PSVirtualMachineExtension psExt) + { + var publicSettings = string.IsNullOrEmpty(psExt.PublicSettings) ? null + : JsonConvert.DeserializeObject(psExt.PublicSettings); + + ResourceGroupName = psExt.ResourceGroupName; + Name = psExt.Name; + Location = psExt.Location; + Etag = psExt.Etag; + Publisher = psExt.Publisher; + ExtensionType = psExt.ExtensionType; + TypeHandlerVersion = psExt.TypeHandlerVersion; + Id = psExt.Id; + PublicSettings = psExt.PublicSettings; + ProtectedSettings = psExt.ProtectedSettings; + ProvisioningState = psExt.ProvisioningState; + Statuses = psExt.Statuses; + UserName = (publicSettings == null) ? null : publicSettings.UserName; + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VirtualMachineExtensionBaseCmdlet.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VirtualMachineExtensionBaseCmdlet.cs new file mode 100644 index 000000000000..e57aa54a5ceb --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Extension/VirtualMachineExtensionBaseCmdlet.cs @@ -0,0 +1,29 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.Compute; + +namespace Microsoft.Azure.Commands.Compute +{ + public abstract class VirtualMachineExtensionBaseCmdlet : ComputeClientBaseCmdlet + { + public IVirtualMachineExtensionsOperations VirtualMachineExtensionClient + { + get + { + return ComputeClient.ComputeManagementClient.VirtualMachineExtensions; + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs new file mode 100644 index 000000000000..6258e05f4f19 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs @@ -0,0 +1,94 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using System.Linq; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineExtensionImage)] + [OutputType(typeof(PSVirtualMachineExtensionImage))] + [OutputType(typeof(PSVirtualMachineExtensionImageDetails))] + public class GetAzureVMExtensionImageCommand : VirtualMachineExtensionImageBaseCmdlet + { + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + public string Location { get; set; } + + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + public string PublisherName { get; set; } + + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + public string Type { get; set; } + + [Parameter, ValidateNotNullOrEmpty] + public string FilterExpression { get; set; } + + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true)] + public string Version { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (string.IsNullOrEmpty(this.Version)) + { + // TODO, FilterExpression + var result = this.VirtualMachineExtensionImageClient.ListVersions(Location.Canonicalize(), PublisherName, Type); + + var images = from r in result + select new PSVirtualMachineExtensionImage + { + Id = r.Id, + Location = r.Location, + Version = r.Name, + PublisherName = this.PublisherName, + Type = this.Type, + FilterExpression = this.FilterExpression + }; + + WriteObject(result, true); + // TODO: Cannot Write the Result from Linq Select. + //WriteObject(images, true); + } + else + { + var result = this.VirtualMachineExtensionImageClient.Get(Location.Canonicalize(), PublisherName, Type, Version); + + var image = new PSVirtualMachineExtensionImageDetails + { + Id = result.Id, + Location = result.Location, + HandlerSchema = result.HandlerSchema, + OperatingSystem = result.OperatingSystem, + ComputeRole = result.ComputeRole, + SupportsMultipleExtensions = result.SupportsMultipleExtensions, + VMScaleSetEnabled = result.VmScaleSetEnabled, + Version = result.Name, + PublisherName = this.PublisherName, + Type = this.Type, + FilterExpression = this.FilterExpression + }; + + WriteObject(image); + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/ExtensionImages/GetAzureVMExtensionImageTypeCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/ExtensionImages/GetAzureVMExtensionImageTypeCommand.cs new file mode 100644 index 000000000000..52eaad14bfe0 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/ExtensionImages/GetAzureVMExtensionImageTypeCommand.cs @@ -0,0 +1,57 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using System.Linq; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineExtensionImageType)] + [OutputType(typeof(PSVirtualMachineExtensionImageType))] + public class GetAzureVMExtensionImageTypeCommand : VirtualMachineExtensionImageBaseCmdlet + { + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + public string Location { get; set; } + + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + public string PublisherName { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + var result = this.VirtualMachineExtensionImageClient.ListTypes(Location.Canonicalize(), PublisherName); + + var images = from r in result + select new PSVirtualMachineExtensionImageType + { + Id = r.Id, + Location = r.Location, + Type = r.Name, + PublisherName = this.PublisherName + }; + + WriteObject(result, true); + // TODO: Cannot Write the Result from Linq Select. + //WriteObject(images, true); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/ExtensionImages/VirtualMachineExtensionImageBaseCmdlet.cs b/src/CLU/Microsoft.Azure.Commands.Compute/ExtensionImages/VirtualMachineExtensionImageBaseCmdlet.cs new file mode 100644 index 000000000000..226a9e74d983 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/ExtensionImages/VirtualMachineExtensionImageBaseCmdlet.cs @@ -0,0 +1,29 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.Compute; + +namespace Microsoft.Azure.Commands.Compute +{ + public abstract class VirtualMachineExtensionImageBaseCmdlet : ComputeClientBaseCmdlet + { + public IVirtualMachineExtensionImagesOperations VirtualMachineExtensionImageClient + { + get + { + return ComputeClient.ComputeManagementClient.VirtualMachineExtensionImages; + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImageCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImageCommand.cs new file mode 100644 index 000000000000..093cdc83975a --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImageCommand.cs @@ -0,0 +1,132 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using System.Linq; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, + ProfileNouns.VirtualMachineImage)] + [OutputType(typeof(PSVirtualMachineImage), + ParameterSetName = new [] {ListVMImageParamSetName})] + [OutputType(typeof(PSVirtualMachineImageDetail), + ParameterSetName = new [] {GetVMImageDetailParamSetName})] + public class GetAzureVMImageCommand : VirtualMachineImageBaseCmdlet + { + protected const string ListVMImageParamSetName = "ListVMImage"; + protected const string GetVMImageDetailParamSetName = "GetVMImageDetail"; + + [Parameter(ParameterSetName = ListVMImageParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = GetVMImageDetailParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + + [Parameter(ParameterSetName = ListVMImageParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = GetVMImageDetailParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string PublisherName { get; set; } + + [Parameter(ParameterSetName = ListVMImageParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = GetVMImageDetailParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string Offer { get; set; } + + [Parameter(ParameterSetName = ListVMImageParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = GetVMImageDetailParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string Skus { get; set; } + + [Parameter(ParameterSetName = ListVMImageParamSetName, + ValueFromPipelineByPropertyName = false), + ValidateNotNullOrEmpty] + public string FilterExpression { get; set; } + + [Parameter(ParameterSetName = GetVMImageDetailParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true), + ValidateNotNullOrEmpty] + public string Version { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (this.ParameterSetName.Equals(ListVMImageParamSetName)) + { + // TODO : FilterExpression + var result = this.VirtualMachineImageClient.List(Location.Canonicalize(), PublisherName, Offer, Skus, null); + + /*var images = from r in result + select new PSVirtualMachineImage + { + Id = r.Id, + Location = r.Location, + Version = r.Name, + PublisherName = this.PublisherName, + Offer = this.Offer, + Skus = this.Skus, + FilterExpression = this.FilterExpression + }; + + WriteObject(images, true);*/ + WriteObject(result, true); + } + else + { + var result = this.VirtualMachineImageClient.Get(Location.Canonicalize(), PublisherName, Offer, Skus, Version); + + /*var image = new PSVirtualMachineImageDetail + { + Id = result.Id, + Location = result.Location, + Name = result.Name, + Version = result.Name, + PublisherName = this.PublisherName, + Offer = this.Offer, + Skus = this.Skus, + OSDiskImage = result.OsDiskImage, + DataDiskImages = result.DataDiskImages, + PurchasePlan = result.Plan, + }; + + WriteObject(image);*/ + WriteObject(result); + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImageOfferCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImageOfferCommand.cs new file mode 100644 index 000000000000..9c4515f0a89b --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImageOfferCommand.cs @@ -0,0 +1,57 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineImageOffer)] + [OutputType(typeof(PSVirtualMachineImageOffer))] + public class GetAzureVMImageOfferCommand : VirtualMachineImageBaseCmdlet + { + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + public string Location { get; set; } + + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + public string PublisherName { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + IList result = this.VirtualMachineImageClient.ListOffers(Location.Canonicalize(), PublisherName); + + /*var images = from r in result + select new PSVirtualMachineImageOffer + { + Id = r.Id, + Location = r.Location, + Offer = r.Name, + PublisherName = this.PublisherName + }; + + WriteObject(images, true);*/ + WriteObject(result, true); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImagePublisherCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImagePublisherCommand.cs new file mode 100644 index 000000000000..1979d384d808 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImagePublisherCommand.cs @@ -0,0 +1,54 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineImagePublisher)] + [OutputType(typeof(PSVirtualMachineImagePublisher))] + public class GetAzureVMImagePublisherCommand : VirtualMachineImageBaseCmdlet + { + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + public string Location { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + IList result = this.VirtualMachineImageClient.ListPublishers(Location.Canonicalize()); + + var images = from r in result + select new PSVirtualMachineImagePublisher + { + Id = r.Id, + Location = r.Location, + PublisherName = r.Name + }; + + WriteObject(result, true); + // TODO: Cannot Write the Result from Linq Select. + //WriteObject(images, true); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImageSkuCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImageSkuCommand.cs new file mode 100644 index 000000000000..1a5cb92f1c70 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Images/GetAzureVMImageSkuCommand.cs @@ -0,0 +1,61 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineImageSku)] + [OutputType(typeof(PSVirtualMachineImageSku))] + public class GetAzureVMImageSkuCommand : VirtualMachineImageBaseCmdlet + { + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + public string Location { get; set; } + + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + public string PublisherName { get; set; } + + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + public string Offer { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + IList result = this.VirtualMachineImageClient.ListSkus(Location.Canonicalize(), PublisherName, Offer); + + /*var images = from r in result + select new PSVirtualMachineImageSku + { + Id = r.Id, + Location = r.Location, + PublisherName = this.PublisherName, + Offer = this.Offer, + Skus = r.Name + }; + + WriteObject(images, true);*/ + WriteObject(result, true); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Images/VirtualMachineImageBaseCmdlet.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Images/VirtualMachineImageBaseCmdlet.cs new file mode 100644 index 000000000000..447ffd664f98 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Images/VirtualMachineImageBaseCmdlet.cs @@ -0,0 +1,29 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.Compute; + +namespace Microsoft.Azure.Commands.Compute +{ + public abstract class VirtualMachineImageBaseCmdlet : ComputeClientBaseCmdlet + { + public IVirtualMachineImagesOperations VirtualMachineImageClient + { + get + { + return ComputeClient.ComputeManagementClient.VirtualMachineImages; + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/MSSharedLibKey.snk b/src/CLU/Microsoft.Azure.Commands.Compute/MSSharedLibKey.snk new file mode 100644 index 000000000000..695f1b38774e Binary files /dev/null and b/src/CLU/Microsoft.Azure.Commands.Compute/MSSharedLibKey.snk differ diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.Types.ps1xml b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.Types.ps1xml new file mode 100644 index 000000000000..345faa61b287 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.Types.ps1xml @@ -0,0 +1,3 @@ + + + diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.dll-Help.psd1 b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.dll-Help.psd1 new file mode 100644 index 000000000000..9d452dc66b06 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.dll-Help.psd1 @@ -0,0 +1,93 @@ +# +# Module manifest for module 'Microsoft.Azure.Commands.Compute' +# +# Generated by: Microsoft Corporation +# +# Generated on: 04/01/2015 +# + +@{ + +# Version number of this module. +ModuleVersion = '0.9.10' + +# ID used to uniquely identify this module +GUID = 'B37DCEB6-F8A8-4C76-B1FC-9C35DFE08977' + +# Author of this module +Author = 'Microsoft Corporation' + +# Company or vendor of this module +CompanyName = 'Microsoft Corporation' + +# Copyright statement for this module +Copyright = 'Microsoft Corporation. All rights reserved.' + +# Description of the functionality provided by this module +Description = '' + +# Minimum version of the Windows PowerShell engine required by this module +PowerShellVersion = '3.0' + +# Name of the Windows PowerShell host required by this module +PowerShellHostName = '' + +# Minimum version of the Windows PowerShell host required by this module +PowerShellHostVersion = '' + +# Minimum version of the .NET Framework required by this module +DotNetFrameworkVersion = '4.5' + +# Minimum version of the common language runtime (CLR) required by this module +CLRVersion='4.0' + +# Processor architecture (None, X86, Amd64, IA64) required by this module +ProcessorArchitecture = 'None' + +# Modules that must be imported into the global environment prior to importing this module +RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module +ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +TypesToProcess = @( + '.\Microsoft.Azure.Commands.Compute.Types.ps1xml' +) + +# Format files (.ps1xml) to be loaded when importing this module +FormatsToProcess = @( + '.\Microsoft.Azure.Commands.Compute.format.ps1xml', + '.\Microsoft.Azure.Commands.Compute.format.generated.ps1xml' +) + +# Modules to import as nested modules of the module specified in ModuleToProcess +NestedModules = @( + '.\Microsoft.Azure.Commands.Compute.dll' +) + +# Functions to export from this module +FunctionsToExport = '*' + +# Cmdlets to export from this module +CmdletsToExport = '*' + +# Variables to export from this module +VariablesToExport = '*' + +# Aliases to export from this module +AliasesToExport = @() + +# List of all modules packaged with this module +ModuleList = @() + +# List of all files packaged with this module +FileList = @() + +# Private data to pass to the module specified in ModuleToProcess +PrivateData = '' + +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.dll-Help.xml b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.dll-Help.xml new file mode 100644 index 000000000000..4041736ad4d8 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.dll-Help.xml @@ -0,0 +1,17111 @@ + + + + + Add-AzureRmVhd + + + + + + + Add + AzureRmVhd + + + + + + + + Add-AzureRmVhd + + ResourceGroupName + + + + String + + + Destination + + + + Uri + + + LocalFilePath + + + + FileInfo + + + NumberOfUploaderThreads + + + + Nullable`1[Int32] + + + BaseImageUriToPatch + + + + Uri + + + OverWrite + + + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + + + String + + String + + + + + + Destination + + + + Uri + + Uri + + + + + + LocalFilePath + + + + FileInfo + + FileInfo + + + + + + NumberOfUploaderThreads + + + + Nullable`1[Int32] + + Nullable`1[Int32] + + + + + + BaseImageUriToPatch + + + + Uri + + Uri + + + + + + OverWrite + + + + SwitchParameter + + SwitchParameter + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Add-AzureRmVMAdditionalUnattendContent + + Adds information to the unattended Windows Setup answer file. + + + + + Add + AzureRmVMAdditionalUnattendContent + + + + The Add-AzureRmVMAdditionalUnattendContent cmdlet adds information to the unattended Windows Setup answer file. Specify additional base 64 encoded XML formatted information that this cmdlet adds to the unattend.xml file. + + + + Add-AzureRmVMAdditionalUnattendContent + + VM + + Specifies the virtual machine object that this cmdlet modifies. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. Create a virtual machine object by using the New-AzureRmVMConfig cmdlet. + + PSVirtualMachine + + + Content + + Specifies base 64 encoded XML formatted content. This cmdlet adds the content to the unattend.xml file. The XML content must be less than 4 KB and must include the root element for the setting or feature that this cmdlet inserts. + + String + + + SettingName + + Specifies the name of the setting to which the content applies. Valid values are: + -- FirstLogonCommands +-- AutoLogon + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + Specifies the virtual machine object that this cmdlet modifies. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. Create a virtual machine object by using the New-AzureRmVMConfig cmdlet. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + Content + + Specifies base 64 encoded XML formatted content. This cmdlet adds the content to the unattend.xml file. The XML content must be less than 4 KB and must include the root element for the setting or feature that this cmdlet inserts. + + String + + String + + + none + + + SettingName + + Specifies the name of the setting to which the content applies. Valid values are: + -- FirstLogonCommands +-- AutoLogon + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Add content to unattend.xml -------------------------- + + PS C:\> + + PS C:\>$AvailabilitySet = Get-AzureRmAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet03" +PS C:\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" -AvailabilitySetID $AvailabilitySet.Id +PS C:\> $Credential = Get-Credential +PS C:\> $VirtualMachine = Set-AzureRmVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName "Contoso26" -Credential $Credential +PS C:\> $AucContent = "<UserAccounts><AdministratorPassword><Value>" + "Password" + "</Value><PlainText>true</PlainText></AdministratorPassword></UserAccounts>"; +PS C:\> $VirtualMachine = Add-AzureRmVMAdditionalUnattendContent -VM $VirtualMachine -Content $AucContent -SettingName "AutoLogon" + + The first command gets the availability set named AvailablitySet03 in the resource group named ResourceGroup11, and then stores that object in the $AvailabilitySet variable. + + + The fourth command uses the Set-AzureRmVMOperatingSystem cmdlet to configure the virtual machine stored in $VirtualMachine. + + + + + + + + + + + + + Get-AzureRmAvailabilitySet + + + + Set-AzureRmVMOperatingSystem + + + + New-AzureRmVMConfig + + + + + + + + Add-AzureRmVMDataDisk + + Adds a data disk to a virtual machine. + + + + + Add + AzureRmVMDataDisk + + + + The Add-AzureRmVMDataDisk cmdlet adds a data disk to a virtual machine. You can add a data disk when you create a virtual machine, or you can add a data disk to an existing virtual machine. + + + + Add-AzureRmVMDataDisk + + VM + + Specifies the local virtual machine object to which to add a data disk. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. Create a virtual machine object by using the New-AzureRmVMConfig cmdlet. + + PSVirtualMachine + + + Name + + Specifies the name of the data disk to add. + + String + + + VhdUri + + Specifies the Uniform Resource Identifier (URI) for the virtual hard disk (VHD) file to create when a platform image or user image is used. This cmdlet copies the image binary large object (BLOB) to this location. This is the location from which to start the virtual machine. + + String + + + Caching + + Specifies the caching mode of the disk. Valid values are: + -- ReadOnly +-- ReadWrite + The default value is ReadWrite. Changing this value causes the virtual machine to restart. + This setting affects the consistency and performance of the disk. + + String + + + DiskSizeInGB + + Specifies the size, in gigabytes, of an empty disk to attach to a virtual machine. + + Nullable`1[Int32] + + + Lun + + Specifies the logical unit number (LUN) for a data disk. + + Nullable`1[Int32] + + + CreateOption + + Specifies whether this cmldet creates a disk in the virtual machine from a platform or user image, creates an empty disk, or attaches an existing disk. Valid values are: + -- Attach +-- Empty +-- FromImage + + String + + + SourceImageUri + + Specifies the source URI of the disk that this cmdlet attaches. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + Specifies the local virtual machine object to which to add a data disk. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. Create a virtual machine object by using the New-AzureRmVMConfig cmdlet. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + Name + + Specifies the name of the data disk to add. + + String + + String + + + none + + + VhdUri + + Specifies the Uniform Resource Identifier (URI) for the virtual hard disk (VHD) file to create when a platform image or user image is used. This cmdlet copies the image binary large object (BLOB) to this location. This is the location from which to start the virtual machine. + + String + + String + + + none + + + Caching + + Specifies the caching mode of the disk. Valid values are: + -- ReadOnly +-- ReadWrite + The default value is ReadWrite. Changing this value causes the virtual machine to restart. + This setting affects the consistency and performance of the disk. + + String + + String + + + none + + + DiskSizeInGB + + Specifies the size, in gigabytes, of an empty disk to attach to a virtual machine. + + Nullable`1[Int32] + + Nullable`1[Int32] + + + none + + + Lun + + Specifies the logical unit number (LUN) for a data disk. + + Nullable`1[Int32] + + Nullable`1[Int32] + + + none + + + CreateOption + + Specifies whether this cmldet creates a disk in the virtual machine from a platform or user image, creates an empty disk, or attaches an existing disk. Valid values are: + -- Attach +-- Empty +-- FromImage + + String + + String + + + none + + + SourceImageUri + + Specifies the source URI of the disk that this cmdlet attaches. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Add data disks to a new virtual machine -------------------------- + + PS C:\> + + PS C:\>$VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" +PS C:\> $DataDiskVhdUri01 = "https://contoso.blob.core.windows.net/test/data1.vhd" +PS C:\> $DataDiskVhdUri02 = "https://contoso.blob.core.windows.net/test/data2.vhd" +PS C:\> $DataDiskVhdUri03 = "https://contoso.blob.core.windows.net/test/data3.vhd" +PS C:\> $VirtualMachine = Add-AzureRmVMDataDisk -VM $VirtualMachine -Name 'DataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri $DataDiskVhdUri1 -CreateOption Empty +PS C:\> $VirtualMachine = Add-AzureRmVMDataDisk -VM $VirtualMachine -Name 'DataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri $DataDiskVhdUri2 -CreateOption Empty +PS C:\> $VirtualMachine = Add-AzureRmVMDataDisk -VM $VirtualMachine -Name 'DataDisk3' -Caching 'ReadOnly' -DiskSizeInGB 12 -Lun 2 -VhdUri $DataDiskVhdUri3 -CreateOption Empty + + The first command creates a virtual machine object, and then stores it in the $VirtualMachine variable. The command assigns a name and size to the virtual machine. + + + + + + + + + + + + + + -------------------------- Example 2: Add a data disk to an existing virtual machine -------------------------- + + PS C:\> + + PS C:\>$VirtualMachine = Get-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" +PS C:\> Add-AzureRmVMDataDisk -VM $VirtualMachine -Name "disk1" -VhdUri "https://contoso.blob.core.windows.net/vhds/diskstandard03.vhd" -LUN 0 -Caching ReadOnly -DiskSizeinGB 1 -CreateOption Empty +PS C:\> Update-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" -VM $VirtualMachine + + The first command gets the virtual machine named VirtualMachine07 by using the Get-AzureRmVM cmdlet. The command stores the virtual machine in the $VirtualMachine variable. + + + + + + + + + + + + + + + + Remove-AzureRmVMDataDisk + + + + Get-AzureRmVM + + + + New-AzureRmVMConfig + + + + + + + + Add-AzureRmVMNetworkInterface + + Adds a network interface to a virtual machine. + + + + + Add + AzureRmVMNetworkInterface + + + + The Add-AzureRmVMNetworkInterface cmdlet adds a network interface to a virtual machine. You can add an interface when you create a virtual machine or add one to an existing virtual machine. + + + + Add-AzureRmVMNetworkInterface + + VM + + Specifies a local virtual machine object to which to add a network interface. To create a virtual machine, use the New-AzureRmVMConfig cmdlet. To obtain an existing virtual machine, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + + Id + + Specifies the ID of a network interface to add to a virtual machine. To obtain a network interface, use the Get-AzureRmNetworkInterface cmdlet. + + String + + + Primary + + Indicates that this cmdlet adds the network interface as the primary interface. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Add-AzureRmVMNetworkInterface + + VM + + Specifies a local virtual machine object to which to add a network interface. To create a virtual machine, use the New-AzureRmVMConfig cmdlet. To obtain an existing virtual machine, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + + NetworkInterface + + + + List`1[PSNetworkInterface] + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + Specifies a local virtual machine object to which to add a network interface. To create a virtual machine, use the New-AzureRmVMConfig cmdlet. To obtain an existing virtual machine, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + Id + + Specifies the ID of a network interface to add to a virtual machine. To obtain a network interface, use the Get-AzureRmNetworkInterface cmdlet. + + String + + String + + + none + + + Primary + + Indicates that this cmdlet adds the network interface as the primary interface. + + SwitchParameter + + SwitchParameter + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + NetworkInterface + + + + List`1[PSNetworkInterface] + + List`1[PSNetworkInterface] + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Add a network interface to a new virtual machine -------------------------- + + PS C:\> + + PS C:\>$VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" +PS C:\> Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id "/subscriptions/46fc8ea4-2de6-4179-8ab1-365da4121af4/resourceGroups/contoso/providers/Microsoft.Network/networkInterfaces/sshNIC" + + The first command creates a virtual machine object, and then stores it in the $VirtualMachine variable. The command assigns a name and size to the virtual machine. + + + + + + + + + + + + + + -------------------------- Example 2: Add a network interface to an existing virtual machine -------------------------- + + PS C:\> + + PS C:\>$VirtualMachine = Get-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" +PS C:\> Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id "/subscriptions/46fc8ea4-2de6-4179-8ab1-365da4121af4/resourceGroups/contoso/providers/Microsoft.Network/networkInterfaces/sshNIC" +PS C:\> Update-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name " VirtualMachine07" -VM $VirtualMachine + + The first command gets the virtual machine named VirtualMachine07 by using the Get-AzureRmVM cmldet. The command stores the virtual machine in the $VirtualMachine variable. + + + + + + + + + + + + + + + + New-AzureRmVMConfig + + + + Get-AzureRmVM + + + + Get-AzureRmAvailabilitySet + + + + + + + + Add-AzureRmVMSecret + + Adds a secret to a virtual machine. + + + + + Add + AzureRmVMSecret + + + + The Add-AzureRmVMSecret cmdlet adds a secret to a virtual machine. This value lets you add a certificate to the virtual machine. The secret needs to be stored in a Key Vault. For more information about Key Vault, see What is Azure Key Vault? (https://azure.microsoft.com/en-us/documentation/articles/key-vault-whatis/) in the Azure library. For more information about the cmdlets, see Azure Key Vault Cmdlets (https://msdn.microsoft.com/library/azure/dn868052.aspx) in the Microsoft Developer Network library or type Get-Help Set-AzureKeyVaultSecret. + + + + Add-AzureRmVMSecret + + VM + + Specifies the virtual machine object that this cmdlet modifies. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. Create a virtual machine object by using the New-AzureRmVMConfig cmdlet. + + PSVirtualMachine + + + SourceVaultId + + Specifies the resource ID of the Key Vault that contains the certificates that you can add to the virtual machine. This value also acts as the key for adding multiple certificates. This means that you can use the same value for SourceVaultId when you add multiple certificates from the same Key Vault. + + String + + + CertificateStore + + Specifies the name of a certificate store on the virtual machine that runs the Windows operating system. This cmdlet adds the certificate to the store that this parameter specifies. You can only specify this parameter for virtual machines that run the Windows operating system. + + String + + + CertificateUrl + + Specifies the URL that points to a Key Vault secret which contains a certificate. + The certificate is the Base64 encoding of the following JavaScript Object Notation (JSON) object, which is encoded in UTF-8. + { +"data": "<Base64-encoded-file>", +"dataType": "<file-format>", +"password": "<pfx-file-password>" +} + Currently, dataType accepts only .pfx files. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + Specifies the virtual machine object that this cmdlet modifies. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. Create a virtual machine object by using the New-AzureRmVMConfig cmdlet. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + SourceVaultId + + Specifies the resource ID of the Key Vault that contains the certificates that you can add to the virtual machine. This value also acts as the key for adding multiple certificates. This means that you can use the same value for SourceVaultId when you add multiple certificates from the same Key Vault. + + String + + String + + + none + + + CertificateStore + + Specifies the name of a certificate store on the virtual machine that runs the Windows operating system. This cmdlet adds the certificate to the store that this parameter specifies. You can only specify this parameter for virtual machines that run the Windows operating system. + + String + + String + + + none + + + CertificateUrl + + Specifies the URL that points to a Key Vault secret which contains a certificate. + The certificate is the Base64 encoding of the following JavaScript Object Notation (JSON) object, which is encoded in UTF-8. + { +"data": "<Base64-encoded-file>", +"dataType": "<file-format>", +"password": "<pfx-file-password>" +} + Currently, dataType accepts only .pfx files. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Add a secret to a virtual machine -------------------------- + + PS C:\> + + PS C:\>$VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" -AvailabilitySetID $AvailabilitySet.Id +PS C:\> $Credential = Get-Credential +PS C:\> $VirtualMachine = Set-AzureRmVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName "Contoso26" -Credential $Credential +PS C:\> $SourceVaultId = "/subscriptions/46f8cea4-2de6-4179-8ab1-365da4211af4/resourceGroups/vault/providers/Microsoft.KeyVault/vaults/keyvault" +PS C:\> $CertificateStore01 = "My" +PS C:\> $CertificateUrl01 = "https://contosovault.vault.azure.net/secrets/514ceb769c984379a7e0230bdd703272" +PS C:\> $VirtualMachine = Add-AzureRmVMSecret -VM $VirtualMachine -SourceVaultId $SourceVaultId -CertificateStore $CertificateStore01 -CertificateUrl $CertificateUrl01 + + The first command creates a virtual machine object, and then stores it in the $VirtualMachine variable. The command assigns a name and size to the virtual machine. + + + The fifth command assigns a source vault ID to the $SourceVaultId variable for later use. The command assumes that the $SubscriptionId variable has an appropriate value. + + + + + + + + + + + + + + + + + Add-AzureRmVMSshPublicKey + + Adds the public keys for SSH for a virtual machine. + + + + + Add + AzureRmVMSshPublicKey + + + + The Add-AzureRmVMSshPublicKey cmdlet adds the public keys that you can use to connect to a virtual machine over Secure Shell (SSH). + + + + Add-AzureRmVMSshPublicKey + + VM + + Specifies the virtual machine object that this cmdlet modifies. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. Create a virtual machine object by using the New-AzureRmVMConfig cmdlet. + + PSVirtualMachine + + + KeyData + + Specifies a base 64 encoding of a public key. You can connect to a virtual machine by using SSH by using the key that this parameter specifies. + + String + + + Path + + Specifies the full path of a file, on the virtual machine, where this cmdlet stores the SSH public key. If the file already exists, this cmdlet appends the key to the file. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + Specifies the virtual machine object that this cmdlet modifies. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. Create a virtual machine object by using the New-AzureRmVMConfig cmdlet. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + KeyData + + Specifies a base 64 encoding of a public key. You can connect to a virtual machine by using SSH by using the key that this parameter specifies. + + String + + String + + + none + + + Path + + Specifies the full path of a file, on the virtual machine, where this cmdlet stores the SSH public key. If the file already exists, this cmdlet appends the key to the file. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Add a public key to a virtual machine -------------------------- + + PS C:\> + + PS C:\>$VirtualMachine = Get-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" +PS C:\> $VirtualMachine = Add-AzureRmVMSshPublicKey -VM $VirtualMachine -KeyData "MIIDszCCApugAwIBAgIJALBV9YJCF/tAMA0GCSq12Ib3DQEB21QUAMEUxCzAJBgNV" -Path "/home/admin/.ssh/authorized_keys" + + The first command gets the virtual machine named VirtualMachine07 by using the Get-AzureRmVM cmdlet. The command stores the virtual machine in the $VirtualMachine variable. + + + + + + + + + + + + + + + + Get-AzureRmVM + + + + + + + + Get-AzureRmAvailabilitySet + + Gets Azure availability sets in a resource group. + + + + + Get + AzureRmAvailabilitySet + + + + The Get-AzureRmAvailabilitySet cmdlet gets Azure availability sets in a resource group. Specify the name of a specific availability set to get. + + + + Get-AzureRmAvailabilitySet + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + Name + + Specifies the name of an availability set to get. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + Name + + Specifies the name of an availability set to get. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get a specific availability set -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet03" + + This command gets the availability set named AvailablitySet03 in the resource group named ResourceGroup11. + + + + + + + + + + + + + + -------------------------- Example 2: Get all availability sets -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmAvailabilitySet -ResourceGroupName "ResourceGroup11" + + This command gets all the availability sets in the resource group named ResourceGroup11. + + + + + + + + + + + + + + + + New-AzureRmAvailabilitySet + + + + Remove-AzureRmAvailabilitySet + + + + + + + + Get-AzureRmRemoteDesktopFile + + Gets an .rdp file. + + + + + Get + AzureRmRemoteDesktopFile + + + + The Get-AzureRmRemoteDesktopFile cmdlet gets a Remote Desktop Protocol (.rdp) file. + + + + Get-AzureRmRemoteDesktopFile + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + Name + + Specifies the name of the availability set that this cmdlet gets. + + String + + + LocalPath + + Specifies the local full path where this cmdlet stores the .rdp file. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Get-AzureRmRemoteDesktopFile + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + Name + + Specifies the name of the availability set that this cmdlet gets. + + String + + + LocalPath + + Specifies the local full path where this cmdlet stores the .rdp file. + + String + + + Launch + + + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + Name + + Specifies the name of the availability set that this cmdlet gets. + + String + + String + + + none + + + LocalPath + + Specifies the local full path where this cmdlet stores the .rdp file. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Launch + + + + SwitchParameter + + SwitchParameter + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get a Remote Desktop file -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmRemoteDesktopFile -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" -LocalPath "D:\RemoteDesktopFile07.rdp" + + This command gets the Remote Desktop file for the virtual machine named VirtualMachine07. The command stores the result in the file named D:\RemoteDesktopFile07.rdp. + + + + + + + + + + + + + + + + + + + + Get-AzureRmVM + + Gets the properties of a virtual machine. + + + + + Get + AzureRmVM + + + + The Get-AzureRmVM cmdlet gets the model view and instance view of an Azure virtual machine. The model view is the user specified properties of the virtual machine. The instance view is the instance level status of the virtual machine. To get only the instance view of a virtual machine, specify the Status parameter. + + + + Get-AzureRmVM + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Get-AzureRmVM + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + Name + + Specifies the name of the virtual machine to get. + + String + + + Status + + Indicates that this cmdlet gets only the instance view of the virtual machine. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Get-AzureRmVM + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Get-AzureRmVM + + NextLink + + Specifies the next link. + + Uri + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + Name + + Specifies the name of the virtual machine to get. + + String + + String + + + none + + + Status + + Indicates that this cmdlet gets only the instance view of the virtual machine. + + SwitchParameter + + SwitchParameter + + + none + + + NextLink + + Specifies the next link. + + Uri + + Uri + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + microsoft.azure.common.authentication.models.azureprofile + + microsoft.azure.common.authentication.models.azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get model and instance view properties -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" + + This command gets the model view and instance view properties of the virtual machine named VirtualMachine07. + + + + + + + + + + + + + + -------------------------- Example 2: Get instance view properties -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" -Status + + This command gets properties of the virtual machine named VirtualMachine07. This command specifies the Status parameter. Therefore, the command gets only the instance view properties. + + + + + + + + + + + + + + -------------------------- Example 3: Get properties for all virtual machines in a resource group -------------------------- + + PS C:\> + + PS C:\> Get-AzureRmVM -ResourceGroupName "ResourceGroup11" + + This command gets properties for all the virtual machines in the resource group named ResourceGroup11. + + + + + + + + + + + + + + -------------------------- Example 4: Get all virtual machines in your subscription -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVM + + This command gets all the virtual machines in your subscription. + + + + + + + + + + + + + + + + New-AzureRmVM + + + + Remove-AzureRmVM + + + + Restart-AzureRmVM + + + + Start-AzureRmVM + + + + Stop-AzureRmVM + + + + Update-AzureRmVM + + + + + + + + Get-AzureRmVMAccessExtension + + Gets information about the VMAccess extension. + + + + + Get + AzureRmVMAccessExtension + + + + The Get-AzureRmVMAccessExtension cmdlet gets information about the Virtual Machine Access (VMAccess) Virtual Machine Extension. + + + + Get-AzureRmVMAccessExtension + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + + VMName + + Specifies the name of a virtual machine. This cmdlet gets information about VMAccess for the virtual machine that this parameter specifies. + + String + + + Name + + Specifies the name of the extension that this cmdlet gets. + + String + + + Status + + Indicates that this cmdlet gets only the instance view of the extension. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + String + + + none + + + VMName + + Specifies the name of a virtual machine. This cmdlet gets information about VMAccess for the virtual machine that this parameter specifies. + + String + + String + + + none + + + Name + + Specifies the name of the extension that this cmdlet gets. + + String + + String + + + none + + + Status + + Indicates that this cmdlet gets only the instance view of the extension. + + SwitchParameter + + SwitchParameter + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get the VMAccess extension -------------------------- + + PS C:\> + + PS C:\>$VMAccessExtension = Get-AzureRmVMAccessExtension -ResourceGroupName "ResourceGroup11" -VMName "VirtualMachine07" -Name "ContosoTest" + + This command gets the VMAccess extension named ContosoTest for the virtual machine named VirtualMachine07. + + + + + + + + + + + + + + -------------------------- Example 2: Get the instance view of the VMAccess extension -------------------------- + + PS C:\> + + PS C:\>$VMAccessExtension = Get-AzureRmVMAccessExtension -ResourceGroupName "ResourceGroup11" -VMName "VirtualMachine0" -Name "ContosoTest" -Status + + This command gets the instance view of the VMAccess extension named ContosoTest for the virtual machine named VirtualMachine07. + + + + + + + + + + + + + + + + Remove-AzureRmVMAccessExtension + + + + Set-AzureRmVMAccessExtension + + + + Get-AzureRmVMExtension + + + + + + + + Get-AzureRmVMBootDiagnosticsData + + + + + + + Get + AzureRmVMBootDiagnosticsData + + + + + + + + Get-AzureRmVMBootDiagnosticsData + + ResourceGroupName + + + + String + + + Name + + + + String + + + Windows + + + + SwitchParameter + + + LocalPath + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Get-AzureRmVMBootDiagnosticsData + + ResourceGroupName + + + + String + + + Name + + + + String + + + Linux + + + + SwitchParameter + + + LocalPath + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + + + String + + String + + + + + + Name + + + + String + + String + + + + + + Windows + + + + SwitchParameter + + SwitchParameter + + + + + + LocalPath + + + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Linux + + + + SwitchParameter + + SwitchParameter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Get-AzureRmVMCustomScriptExtension + + Gets information about a custom script extension. + + + + + Get + AzureRmVMCustomScriptExtension + + + + The Get-AzureRmVMCustomScriptExtension cmdlet gets information about a custom script Virtual Machine Extension on a virtual machine. + + + + Get-AzureRmVMCustomScriptExtension + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + + VMName + + Specifies the name of a virtual machine for which this cmdlet gets the custom script extension. + + String + + + Name + + Specifies the name of the custom script extension about which this cmdlet gets information. + + String + + + Status + + Indicates that this cmdlet gets the instance view of the custom script extension. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + String + + + none + + + VMName + + Specifies the name of a virtual machine for which this cmdlet gets the custom script extension. + + String + + String + + + none + + + Name + + Specifies the name of the custom script extension about which this cmdlet gets information. + + String + + String + + + none + + + Status + + Indicates that this cmdlet gets the instance view of the custom script extension. + + SwitchParameter + + SwitchParameter + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get a custom script extension -------------------------- + + PS C:\> + + PS C:\>$VMCustomScriptExtension = Get-AzureRmVMCustomScriptExtension -ResourceGroupName "ResourceGroup11" -VMName "VirtualMachine07" -Name "ContosoCustomScript" + + This command gets the custom script extension named ContosoCustomScript for the virtual machine named VirtualMachine07. + + + + + + + + + + + + + + -------------------------- Example 2: Get the instance view of a custom script extension -------------------------- + + PS C:\> + + PS C:\>$VMCustomScriptExtension = Get-AzureRmVMCustomScriptExtension -ResourceGroupName "ResourceGroup11" -VMName "VirtualMachine07" -Name "ContosoCustomScript" -Status + + This command gets the instance view of the custom script extension named ContosoCustomScript for the virtual machine named VirtualMachine07. + + + + + + + + + + + + + + + + Get-AzureRmVMExtension + + + + Get-AzureRmVMExtensionImage + + + + Get-AzureRmVMAccessExtension + + + + + + + + Get-AzureRmVMDiagnosticsExtension + + + + + + + Get + AzureRmVMDiagnosticsExtension + + + + + + + + Get-AzureRmVMDiagnosticsExtension + + ResourceGroupName + + + + String + + + VMName + + + + String + + + Name + + + + String + + + Status + + + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + + + String + + String + + + + + + VMName + + + + String + + String + + + + + + Name + + + + String + + String + + + + + + Status + + + + SwitchParameter + + SwitchParameter + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Get-AzureRmVMDiskEncryptionStatus + + Get-AzureRmVMDiskEncryptionStatus cmdlet displays the encryption status of the VM. It displays encryption status of the OS and Data volumes. In addition to encryption status, it also displays the secret URL and resource ID of the KeyVault where the encryption key for OS volume is present. + + + + + Get + AzureRmVMDiskEncryptionStatus + + + + + + + + Get-AzureRmVMDiskEncryptionStatus + + ResourceGroupName + + Resource group name of the virtual machine + + String + + + VMName + + Name of the virtual machine + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Resource group name of the virtual machine + + String + + String + + + + + + VMName + + Name of the virtual machine + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + + PS C:\> + + $rgName = 'MyResourceGroup'; +$vmName = 'MyWindowsVM'; +Get-AzureRmVmDiskEncryptionStatus -ResourceGroupName $rgname -VMName $vmName; + + + + + + + + + + + + + + + + + + + + + + Get-AzureRmVMDscExtension + + Gets the settings of the DSC extension on a particular VM + + + + + Get + AzureRmVMDscExtension + + + + Gets the settings of the DSC extension on a particular VM. + + + + Get-AzureRmVMDscExtension + + ResourceGroupName + + The resource group name. + + String + + + VMName + + The virtual machine name + + String + + + Name + + Name of the ARM resource that represents the extension. The Set-AzureRmVMDscExtension cmdlet sets this name to 'Microsoft.Powershell.DSC', which is the same value used by Get-AzureRmVMDscExtension. Specify this parameter only if you changed the default name in the Set cmdlet or used a different resource name in an ARM template. + + String + + + Status + + Output shows status when the switch is present + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + The resource group name. + + String + + String + + + + + + VMName + + The virtual machine name + + String + + String + + + + + + Name + + Name of the ARM resource that represents the extension. The Set-AzureRmVMDscExtension cmdlet sets this name to 'Microsoft.Powershell.DSC', which is the same value used by Get-AzureRmVMDscExtension. Specify this parameter only if you changed the default name in the Set cmdlet or used a different resource name in an ARM template. + + String + + String + + + + + + Status + + Output shows status when the switch is present + + SwitchParameter + + SwitchParameter + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + Microsoft.Azure.Commands.Compute.Extension.DSC.VirtualMachineDscExtensionContext + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\> + + Get-AzureRmVMDscExtension -ResourceGroupName Name -VMName VM -Name 'DSC' + + Description + + + + + + + + + + + + + + + + Unknown + + + + + + + + Get-AzureRmVMDscExtensionStatus + + Used to get the status of the DSC extension handler for a VM in a resource group. When a configuration is applied this cmdlet produces output consistent with Start-DscConfiguration. + + + + + Get + AzureRmVMDscExtensionStatus + + + + + + + + Get-AzureRmVMDscExtensionStatus + + ResourceGroupName + + The resource group name. + + String + + + VMName + + The virtual machine name + + String + + + Name + + Name of the ARM resource that represents the extension. The Set-AzureRmVMDscExtension cmdlet sets this name to 'Microsoft.Powershell.DSC', which is the same value used by Get-AzureRmVMDscExtensionStatus. Specify this parameter only if you changed the default name in the Set cmdlet or used a different resource name in an ARM template. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + The resource group name. + + String + + String + + + + + + VMName + + The virtual machine name + + String + + String + + + + + + Name + + Name of the ARM resource that represents the extension. The Set-AzureRmVMDscExtension cmdlet sets this name to 'Microsoft.Powershell.DSC', which is the same value used by Get-AzureRmVMDscExtensionStatus. Specify this parameter only if you changed the default name in the Set cmdlet or used a different resource name in an ARM template. + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + + + Unknown + + + + + + + + Get-AzureRmVMExtension + + Gets properties of Virtual Machine Extensions installed on a virtual machine. + + + + + Get + AzureRmVMExtension + + + + The Get-AzureRmVMExtension cmdlet gets properties of Virtual Machine Extensions installed on a virtual machine. Specify the name of an extension for which to get properties. To get only the instance view of an extension, specify the Status parameter. + + + + Get-AzureRmVMExtension + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + VMName + + Specifies the name of a virtual machine. This cmdlet gets properties of an extension from the virtual machine that this parameter specifies. + + String + + + Name + + Specifies the name of an extension. This cmdlet gets properties for the extension that this parameter specifies. + + String + + + Status + + Indicates that this cmdlet gets only the instance view of an extension. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + VMName + + Specifies the name of a virtual machine. This cmdlet gets properties of an extension from the virtual machine that this parameter specifies. + + String + + String + + + none + + + Name + + Specifies the name of an extension. This cmdlet gets properties for the extension that this parameter specifies. + + String + + String + + + none + + + Status + + Indicates that this cmdlet gets only the instance view of an extension. + + SwitchParameter + + SwitchParameter + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get properties of an extension -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMExtension -ResourceGroupName "ResourceGroup11" -VMName "VirtualMachine22" -Name "CustomScriptExtension" + + This command gets properties for the extension named CustomScriptExtension on the virtual machine named VirtualMachine22 in the resource group ResourceGroup11. + + + + + + + + + + + + + + -------------------------- Example 2: Get instance view of an extension -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMExtension -ResourceGroupName "ResourceGroup11" -VMName "VirtualMachine22" -Name "CustomScriptExtension" -Status + + This command gets the instance view for the extension named CustomScriptExtension on the virtual machine named VirtualMachine22 in the resource group ResourceGroup11. + + + + + + + + + + + + + + + + Remove-AzureRmVMExtension + + + + Set-AzureRmVMExtension + + + + + + + + Get-AzureRmVmExtensionImage + + Gets all versions for an Azure extension. + + + + + Get + AzureRmVmExtensionImage + + + + The Get-AzureRmVMExtensionImage cmdlet gets all versions for an Azure extension. + + + + Get-AzureRmVmExtensionImage + + Location + + Specifies the location of an extension. + + String + + + PublisherName + + Specifies the name of an extension publisher. To obtain an extension publisher, use the Get-AzureRmVMImagePublisher cmdlet. + + String + + + Type + + Specifies the type of the extension. To obtain an extension type, use the Get-AzureRmVMExtensionImageType cmdlet. + + String + + + FilterExpression + + Specifies a filter expression. + + String + + + Version + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Location + + Specifies the location of an extension. + + String + + String + + + none + + + PublisherName + + Specifies the name of an extension publisher. To obtain an extension publisher, use the Get-AzureRmVMImagePublisher cmdlet. + + String + + String + + + none + + + Type + + Specifies the type of the extension. To obtain an extension type, use the Get-AzureRmVMExtensionImageType cmdlet. + + String + + String + + + none + + + FilterExpression + + Specifies a filter expression. + + String + + String + + + none + + + Version + + + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get the versions of an extension image -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMExtensionImage -Location "Central US" -PublisherName "Fabrikam" -Type "FabrikamEndpointProtection" + + This command gets all the versions of the extension image for the specified location, publisher, and type. + + + + + + + + + + + + + + + + Get-AzureRmVMExtensionImageType + + + + Get-AzureRmVMImage + + + + Get-AzureRmVMImagePublisher + + + + Get-AzureRmVMExtensionImageType + + + + + + + + Get-AzureRmVMExtensionImageType + + Gets the type of an Azure extension. + + + + + Get + AzureRmVMExtensionImageType + + + + The Get-AzureRmVMExtensionImageType cmdlet gets the type of an Azure extension. + + + + Get-AzureRmVMExtensionImageType + + Location + + Specifies the location of an extension. This cmdlet gets the type for an extension at the location that this parameter specifies. + + String + + + PublisherName + + Specifies the name of a publisher of an extension. To obtain an extension publisher, use the Get-AzureRmVMImagePublisher cmdlet. This cmdlet gets the type for an extension from the publisher that this parameter specifies. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Location + + Specifies the location of an extension. This cmdlet gets the type for an extension at the location that this parameter specifies. + + String + + String + + + none + + + PublisherName + + Specifies the name of a publisher of an extension. To obtain an extension publisher, use the Get-AzureRmVMImagePublisher cmdlet. This cmdlet gets the type for an extension from the publisher that this parameter specifies. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get an extension image type -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMExtensionImageType -Location "Central US" -PublisherName "Fabrikam" + + This command gets the extension image type for the specified publisher and location. + + + + + + + + + + + + + + + + Get-AzureRmVMExtensionImage + + + + + + + + Get-AzureRmVMImage + + Gets all the versions of a VMImage. + + + + + Get + AzureRmVMImage + + + + The Get-AzureRmVMImage cmdlet gets all the versions of a VMImage. + + + + Get-AzureRmVMImage + + Location + + Specifies the location of a VMImage. + + String + + + PublisherName + + Specifies the publisher of a VMImage. To obtain an image publisher, use the Get-AzureRmVMImagePublisher cmdlet. + + String + + + Offer + + Specifies the type of VMImage offer. To obtain an image offer, use the Get-AzureRmVMImageOffer cmdlet. + + String + + + Skus + + Specifies a VMImage SKU. To obtain an SKU, use the Get-AzureRmVMImageSku cmdlet. + + String + + + FilterExpression + + Specifies a filter expression. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Get-AzureRmVMImage + + Location + + Specifies the location of a VMImage. + + String + + + PublisherName + + Specifies the publisher of a VMImage. To obtain an image publisher, use the Get-AzureRmVMImagePublisher cmdlet. + + String + + + Offer + + Specifies the type of VMImage offer. To obtain an image offer, use the Get-AzureRmVMImageOffer cmdlet. + + String + + + Skus + + Specifies a VMImage SKU. To obtain an SKU, use the Get-AzureRmVMImageSku cmdlet. + + String + + + Version + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Location + + Specifies the location of a VMImage. + + String + + String + + + none + + + PublisherName + + Specifies the publisher of a VMImage. To obtain an image publisher, use the Get-AzureRmVMImagePublisher cmdlet. + + String + + String + + + none + + + Offer + + Specifies the type of VMImage offer. To obtain an image offer, use the Get-AzureRmVMImageOffer cmdlet. + + String + + String + + + none + + + Skus + + Specifies a VMImage SKU. To obtain an SKU, use the Get-AzureRmVMImageSku cmdlet. + + String + + String + + + none + + + FilterExpression + + Specifies a filter expression. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Version + + + + String + + String + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + microsoft.azure.common.authentication.models.azureprofile + + microsoft.azure.common.authentication.models.azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get VMImage objects -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMImage -Location "Central US" -PublisherName "Canonical" -Offer "UbuntuServer" -Skus "15.04-DAILY" + + This command gets all the versions of VMImage that match the specified values. + + + + + + + + + + + + + + + + Get-AzureRmVMImageOffer + + + + Get-AzureRmVMImagePublisher + + + + Get-AzureRmVMImageSku + + + + Save-AzureRmVMImage + + + + + + + + Get-AzureRmVMImageOffer + + Gets VMImage offer types. + + + + + Get + AzureRmVMImageOffer + + + + The Get-AzureRmVMImageOffer cmdlet gets the VMImage offer types. + + + + Get-AzureRmVMImageOffer + + Location + + Specifies the location of the VMImage. + + String + + + PublisherName + + Specifies the name of a publisher of a VMImage. To obtain a publisher, use the Get-AzureRmVMImagePublisher cmdlet. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Location + + Specifies the location of the VMImage. + + String + + String + + + none + + + PublisherName + + Specifies the name of a publisher of a VMImage. To obtain a publisher, use the Get-AzureRmVMImagePublisher cmdlet. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get offer types for a publisher -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMImageOffer -Location "Central US" -PublisherName "Fabrikam" + + This command gets the offer types for the specified publisher in the Central US region. + + + + + + + + + + + + + + + + Get-AzureRmVMImage + + + + Get-AzureRmVMImagePublisher + + + + Get-AzureRmVMImageSku + + + + Save-AzureRmVMImage + + + + + + + + Get-AzureRmVMImagePublisher + + Gets the VMImage publishers. + + + + + Get + AzureRmVMImagePublisher + + + + The Get-AzureRmVMImagePublisher cmdlet gets the VMImage publishers. + + + + Get-AzureRmVMImagePublisher + + Location + + Specifies the location of the VMImage. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Location + + Specifies the location of the VMImage. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get VMImage publishers for a region -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMImagePublisher -Location "Central US" + + This command gets the publishers of VMImage instances for the Central US region within your profile. + + + + + + + + + + + + + + + + Get-AzureRmVMImage + + + + Get-AzureRmVMImageOffer + + + + Get-AzureRmVMImageSku + + + + Save-AzureRmVMImage + + + + + + + + Get-AzureRmVMImageSku + + Gets VMImage SKUs. + + + + + Get + AzureRmVMImageSku + + + + The Get-AzureRmVMImageSku cmdlet gets VMImage SKUs. + + + + Get-AzureRmVMImageSku + + Location + + Specifies the location of the VMImage. + + String + + + PublisherName + + Specifies the publisher of a VMImage. + + String + + + Offer + + Specifies the type of VMImage offer. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Location + + Specifies the location of the VMImage. + + String + + String + + + none + + + PublisherName + + Specifies the publisher of a VMImage. + + String + + String + + + none + + + Offer + + Specifies the type of VMImage offer. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get SKUs -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMImageSku -Location "Central US" -PublisherName "Fabrikam" -Offer "LinuxServer" + + This command gets the SKUs for the specified publisher and offer. + + + + + + + + + + + + + + + + Get-AzureRmVMImage + + + + Get-AzureRmVMImageOffer + + + + Get-AzureRmVMImagePublisher + + + + Save-AzureRmVMImage + + + + + + + + Get-AzureRmVMSize + + Gets available virtual machine sizes. + + + + + Get + AzureRmVMSize + + + + The Get-AzureRmVMSize cmdlet gets available virtual machine sizes. + + + + Get-AzureRmVMSize + + Location + + Specifies the location for which this cmdlet gets the available virtual machine sizes. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Get-AzureRmVMSize + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + + VMName + + Specifies the name of the virtual machine that this cmdlet gets the available virtual machine sizes for resizing. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Get-AzureRmVMSize + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + + AvailabilitySetName + + Specifies the name of the Availability Set for which this cmdlet gets the available virtual machine sizes. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Location + + Specifies the location for which this cmdlet gets the available virtual machine sizes. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + String + + + none + + + VMName + + Specifies the name of the virtual machine that this cmdlet gets the available virtual machine sizes for resizing. + + String + + String + + + none + + + AvailabilitySetName + + Specifies the name of the Availability Set for which this cmdlet gets the available virtual machine sizes. + + String + + String + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get sizes for a location -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMSize -Location "Central US" + + This command gets the available sizes for virtual machines in the specified location. + + + + + + + + + + + + + + -------------------------- Example 2: Get sizes for an availability set -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMSize -ResourceGroupName "ResourceGroup03" -AvailabilitySetName "AvailabilitySet17" + + This command gets available sizes for virtual machines that you can deploy in the availability set named AvailabilitySet17. + + + + + + + + + + + + + + -------------------------- Example 3: Get sizes for an existing virtual machine -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMSize -ResourceGroupName "ResourceGroup03" -VMName "VirtualMachine12" + + This command gets available sizes for the existing virtual machine named VirtualMachine12. You can resize this virtual machine to the sizes that this command gets. + + + + + + + + + + + + + + + + Get-AzureRmVM + + + + + + + + Get-AzureRmVMSqlServerExtension + + + + + + + Get + AzureRmVMSqlServerExtension + + + + + + + + Get-AzureRmVMSqlServerExtension + + ResourceGroupName + + + + String + + + VMName + + + + String + + + Name + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + + + String + + String + + + + + + VMName + + + + String + + String + + + + + + Name + + + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Get-AzureRmVMUsage + + Gets the virtual machine core count usage for a location. + + + + + Get + AzureRmVMUsage + + + + The Get-AzureRmVMUsage cmdlet gets the virtual machine core count usage for a location. + + + + Get-AzureRmVMUsage + + Location + + Specifies the location for which this cmdlet gets virtual machine core count usage. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Location + + Specifies the location for which this cmdlet gets virtual machine core count usage. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Get core count usage for a location -------------------------- + + PS C:\> + + PS C:\>Get-AzureRmVMUsage -Location "Central US" + + This command gets the virtual machine core count usage for the location Central US. + + + + + + + + + + + + + + + + + + + + New-AzureRmAvailabilitySet + + Creates an Azure availability set. + + + + + New + AzureRmAvailabilitySet + + + + The New-AzureRmAvailabilitySet cmdlet creates an Azure availability set. + + + + New-AzureRmAvailabilitySet + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + Name + + Specifies a name for the availability set. + + String + + + Location + + Specifies the location for the availability set. + + String + + + PlatformUpdateDomainCount + + Specifies the platform update domain count. + + Nullable`1[Int32] + + + PlatformFaultDomainCount + + Specifies the platform fault domain count. + + Nullable`1[Int32] + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + Name + + Specifies a name for the availability set. + + String + + String + + + none + + + Location + + Specifies the location for the availability set. + + String + + String + + + none + + + PlatformUpdateDomainCount + + Specifies the platform update domain count. + + Nullable`1[Int32] + + Nullable`1[Int32] + + + none + + + PlatformFaultDomainCount + + Specifies the platform fault domain count. + + Nullable`1[Int32] + + Nullable`1[Int32] + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Create an availability set -------------------------- + + PS C:\> + + PS C:\>New-AzureRmAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet03" -Location "West US" + + This command creates an availability set named AvailablitySet03 in the resource group named ResourceGroup11. + + + + + + + + + + + + + + + + Get-AzureRmAvailabilitySet + + + + Remove-AzureRmAvailabilitySet + + + + + + + + New-AzureRmVM + + Creates a virtual machine. + + + + + New + AzureRmVM + + + + The New-AzureRmVM cmdlet creates a virtual machine in Azure. This cmdlet takes a virtual machine object as input. Use the New-AzureRmVMConfig cmdlet to create a virtual machine object. Configure the virtual machine object by using other cmdlets, such as Set-AzureRmVMOperatingSystem, Set-AzureRmVMSourceImage, Add-AzureRmVMNetworkInterface, and Set-AzureRmVMOSDisk. + + + + New-AzureRmVM + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + Location + + Specifies a location for the virtual machine. + + String + + + VM + + Specifies a local virtual machine to create. To obtain a virtual machine object, use the New-AzureRmVMConfig cmdlet. Configure the virtual machine by using other cmdlets, such as Set-AzureRmVMOperatingSystem, Set-AzureRmVMSourceImage, and Add-AzureRmVMNetworkInterface. + + PSVirtualMachine + + + Tags + + + + Hashtable[] + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + Location + + Specifies a location for the virtual machine. + + String + + String + + + none + + + VM + + Specifies a local virtual machine to create. To obtain a virtual machine object, use the New-AzureRmVMConfig cmdlet. Configure the virtual machine by using other cmdlets, such as Set-AzureRmVMOperatingSystem, Set-AzureRmVMSourceImage, and Add-AzureRmVMNetworkInterface. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + Tags + + + + Hashtable[] + + Hashtable[] + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Name + + Specifies a name for the virtual machine. + + string + + string + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Create a virtual machine -------------------------- + + PS C:\> + + PS C:\># Variables +## Global +$ResourceGroupName = "ResourceGroup11" +$Location = "westeurope" + +## Storage +$StorageName = "GeneralStorage6cc" +$StorageType = "Standard_GRS" + +## Network +$InterfaceName = "ServerInterface06" +$Subnet1Name = "Subnet1" +$VNetName = "VNet09" +$VNetAddressPrefix = "10.0.0.0/16" +$VNetSubnetAddressPrefix = "10.0.0.0/24" + +## Compute +$VMName = "VirtualMachine12" +$ComputerName = "Server22" +$VMSize = "Standard_A2" +$OSDiskName = $VMName + "osDisk" + +# Resource Group +New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location + +# Storage +$StorageAccount = New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageName -Type $StorageType -Location $Location + +# Network +$PIp = New-AzureRmPublicIpAddress -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -AllocationMethod Dynamic +$SubnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name $Subnet1Name -AddressPrefix $VNetSubnetAddressPrefix +$VNet = New-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $ResourceGroupName -Location $Location -AddressPrefix $VNetAddressPrefix -Subnet $SubnetConfig +$Interface = New-AzureRmNetworkInterface -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -SubnetId $VNet.Subnets[0].Id -PublicIpAddressId $PIp.Id + +# Compute + +## Setup local VM object +$Credential = Get-Credential +$VirtualMachine = New-AzureRmVMConfig -VMName $VMName -VMSize $VMSize +$VirtualMachine = Set-AzureRmVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName $ComputerName -Credential $Credential -ProvisionVMAgent -EnableAutoUpdate +$VirtualMachine = Set-AzureRmVMSourceImage -VM $VirtualMachine -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest" +$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $Interface.Id +$OSDiskUri = $StorageAccount.PrimaryEndpoints.Blob.ToString() + "vhds/" + $OSDiskName + ".vhd" +$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name $OSDiskName -VhdUri $OSDiskUri -CreateOption FromImage + +## Create the VM in Azure +New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $VirtualMachine + + This example script shows how to create a virtual machine. This script uses several other cmdlets. + + + + + + + + + + + + + + + + Get-AzureRmVM + + + + Remove-AzureRmVM + + + + Restart-AzureRmVM + + + + Start-AzureRmVM + + + + Stop-AzureRmVM + + + + Update-AzureRmVM + + + + Add-AzureRmVMDataDisk + + + + Add-AzureRmVMNetworkInterface + + + + New-AzureRmVMConfig + + + + Set-AzureRmVMOperatingSystem + + + + Set-AzureRmVMSourceImage + + + + Set-AzureRmVMOSDisk + + + + + + + + New-AzureRmVMConfig + + Creates a configurable virtual machine object. + + + + + New + AzureRmVMConfig + + + + The New-AzureRmVMConfig cmdlet creates a configurable local virtual machine object for Azure. Configure a virtual machine object by using other cmdlets, such as Set-AzureRmVMOperatingSystem, Set-AzureRmVMSourceImage, Add-AzureRmVMNetworkInterface, and Set-AzureRmVMOSDisk. + + + + New-AzureRmVMConfig + + VMName + + Specifies a name for the virtual machine. + + String + + + VMSize + + Specifies the size for the virtual machine. + + String + + + AvailabilitySetId + + Specifies the ID of an availability set. To obtain an availability set object, use the Get-AzureRmAvailabilitySet cmdlet. The availability set object contains an ID property. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VMName + + Specifies a name for the virtual machine. + + String + + String + + + none + + + VMSize + + Specifies the size for the virtual machine. + + String + + String + + + none + + + AvailabilitySetId + + Specifies the ID of an availability set. To obtain an availability set object, use the Get-AzureRmAvailabilitySet cmdlet. The availability set object contains an ID property. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Create a virtual machine object -------------------------- + + PS C:\> + + PS C:\>$AvailabilitySet = Get-AzureRmAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet03" +PS C:\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" -AvailabilitySetID $AvailabilitySet.Id + + The first command gets the availability set named AvailablitySet03 in the resource group named ResourceGroup11, and then stores that object in the $AvailabilitySet variable. + + + + + + + + + + + + + + + + Update-AzureRmVM + + + + Set-AzureRmVMOperatingSystem + + + + Set-AzureRmVMSourceImage + + + + Get-AzureRmAvailabilitySet + + + + + + + + New-AzureVMSqlServerAutoBackupConfig + + + + + + + New + AzureVMSqlServerAutoBackupConfig + + + + + + + + New-AzureVMSqlServerAutoBackupConfig + + ResourceGroupName + + + + String + + + Enable + + + + SwitchParameter + + + RetentionPeriodInDays + + + + Int32 + + + EnableEncryption + + + + SwitchParameter + + + CertificatePassword + + + + SecureString + + + StorageUri + + + + Uri + + + StorageKey + + + + SecureString + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + New-AzureVMSqlServerAutoBackupConfig + + ResourceGroupName + + + + String + + + Enable + + + + SwitchParameter + + + RetentionPeriodInDays + + + + Int32 + + + EnableEncryption + + + + SwitchParameter + + + CertificatePassword + + + + SecureString + + + StorageContext + + + + AzureStorageContext + + + StorageUri + + + + Uri + + + StorageKey + + + + SecureString + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + + + String + + String + + + + + + Enable + + + + SwitchParameter + + SwitchParameter + + + + + + RetentionPeriodInDays + + + + Int32 + + Int32 + + + + + + EnableEncryption + + + + SwitchParameter + + SwitchParameter + + + + + + CertificatePassword + + + + SecureString + + SecureString + + + + + + StorageUri + + + + Uri + + Uri + + + + + + StorageKey + + + + SecureString + + SecureString + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + StorageContext + + + + AzureStorageContext + + AzureStorageContext + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + New-AzureVMSqlServerAutoPatchingConfig + + + + + + + New + AzureVMSqlServerAutoPatchingConfig + + + + + + + + New-AzureVMSqlServerAutoPatchingConfig + + Enable + + + + SwitchParameter + + + DayOfWeek + + + + String + + + MaintenanceWindowStartingHour + + + + Int32 + + + MaintenanceWindowDuration + + + + Int32 + + + PatchCategory + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Enable + + + + SwitchParameter + + SwitchParameter + + + + + + DayOfWeek + + + + String + + String + + + + + + MaintenanceWindowStartingHour + + + + Int32 + + Int32 + + + + + + MaintenanceWindowDuration + + + + Int32 + + Int32 + + + + + + PatchCategory + + + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Publish-AzureRmVMDscConfiguration + + Uploads a Desired State Configuration script to Azure blob storage, which later can be applied to Azure Virtual Machines using the Set-AzureRmVMDscExtension cmdlet. + + + + + Publish + AzureRmVMDscConfiguration + + + + Uploads a Desired State Configuration script to Azure blob storage, which later can be applied to Azure Virtual Machines using the Set-AzureRmVMDscExtension cmdlet. + + + + Publish-AzureRmVMDscConfiguration + + ResourceGroupName + + The name of the resource group that contains the storage account + + String + + + ConfigurationPath + + Path to a file containing one or more configurations. The file can be a PowerShell script (.ps1 file), module (.psm1 file). + + String + + + ContainerName + + Name of the Azure Storage Container the configuration is uploaded to. + + String + + + StorageAccountName + + The Azure Storage Account name used to upload the configuration script to the container specified by ContainerName + + String + + + StorageEndpointSuffix + + Suffix for the storage end point, e.g. core.windows.net + + String + + + Force + + By default Publish-AzureRmVMDscConfiguration will not overwrite any existing blobs or files. Use -Force to overwrite them. + + SwitchParameter + + + SkipDependencyDetection + + Excludes DSC resource dependencies from the configuration archive. + + SwitchParameter + + + ConfigurationDataPath + + Path to a .psd1 file that specifies the data for the Configuration. This is added to the configuration archive and then passed to the configuration function. It gets overwritten by the configuration data path provided through the Set-AzureRmVMDscExtension cmdlet + + String + + + AdditionalPath + + Path to a file or a directory to include in the configuration archive. It gets downloaded to the VM along with the configuration + + String[] + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + WhatIf + + Describes what would happen if you executed the command without actually executing the command. + + SwitchParameter + + + Confirm + + Prompts you for confirmation before executing the command. + + SwitchParameter + + + + Publish-AzureRmVMDscConfiguration + + ConfigurationPath + + Path to a file containing one or more configurations. The file can be a PowerShell script (.ps1 file), module (.psm1 file). + + String + + + OutputArchivePath + + Path to a local ZIP file to write the configuration archive to. When this parameter is used, the configuration script is not uploaded to Azure blob storage. + + String + + + Force + + By default Publish-AzureRmVMDscConfiguration will not overwrite any existing blobs or files. Use -Force to overwrite them. + + SwitchParameter + + + SkipDependencyDetection + + Excludes DSC resource dependencies from the configuration archive. + + SwitchParameter + + + ConfigurationDataPath + + Path to a .psd1 file that specifies the data for the Configuration. This is added to the configuration archive and then passed to the configuration function. It gets overwritten by the configuration data path provided through the Set-AzureRmVMDscExtension cmdlet + + String + + + AdditionalPath + + Path to a file or a directory to include in the configuration archive. It gets downloaded to the VM along with the configuration + + String[] + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + WhatIf + + Describes what would happen if you executed the command without actually executing the command. + + SwitchParameter + + + Confirm + + Prompts you for confirmation before executing the command. + + SwitchParameter + + + + + + ResourceGroupName + + The name of the resource group that contains the storage account + + String + + String + + + + + + ConfigurationPath + + Path to a file containing one or more configurations. The file can be a PowerShell script (.ps1 file), module (.psm1 file). + + String + + String + + + + + + ContainerName + + Name of the Azure Storage Container the configuration is uploaded to. + + String + + String + + + + + + StorageAccountName + + The Azure Storage Account name used to upload the configuration script to the container specified by ContainerName + + String + + String + + + + + + StorageEndpointSuffix + + Suffix for the storage end point, e.g. core.windows.net + + String + + String + + + + + + Force + + By default Publish-AzureRmVMDscConfiguration will not overwrite any existing blobs or files. Use -Force to overwrite them. + + SwitchParameter + + SwitchParameter + + + + + + SkipDependencyDetection + + Excludes DSC resource dependencies from the configuration archive. + + SwitchParameter + + SwitchParameter + + + + + + ConfigurationDataPath + + Path to a .psd1 file that specifies the data for the Configuration. This is added to the configuration archive and then passed to the configuration function. It gets overwritten by the configuration data path provided through the Set-AzureRmVMDscExtension cmdlet + + String + + String + + + + + + AdditionalPath + + Path to a file or a directory to include in the configuration archive. It gets downloaded to the VM along with the configuration + + String[] + + String[] + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + WhatIf + + Describes what would happen if you executed the command without actually executing the command. + + SwitchParameter + + SwitchParameter + + + + + + Confirm + + Prompts you for confirmation before executing the command. + + SwitchParameter + + SwitchParameter + + + + + + OutputArchivePath + + Path to a local ZIP file to write the configuration archive to. When this parameter is used, the configuration script is not uploaded to Azure blob storage. + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\> + + Publish-AzureRmVMDscConfiguration .\MyConfiguration.ps1 + + Description + + + + + + + + + + + + + + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\> + + Publish-AzureRmVMDscConfiguration .\MyConfiguration.ps1 -OutputArchivePath .\MyConfiguration.ps1.zip + + Description + + + + + + + + + + + + + + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\> + + Publish-AzureRmVMDscConfiguration -ConfigurationPath 'C:\Sample.ps1 -SkipDependencyDetection + + Description + + + + + + + + + + + + + + -------------------------- EXAMPLE 4 -------------------------- + + PS C:\> + + Publish-AzureRmVMDscConfiguration -ConfigurationPath C:\Sample.ps1 -ConfigurationDataPath 'C:\SampleData.psd1' + + Description + + + + + + + + + + + + + + -------------------------- EXAMPLE 5 -------------------------- + + PS C:\> + + Publish-AzureRmVMDscConfiguration -ConfigurationPath "C:\Sample.ps1" -AdditionalPath @("C:\ContentDir1", "C:\File.txt") -ConfigurationDataPath "C:\SampleData.psd1" + + Description + + + + + + + + + + + + + + + + Unknown + + + + + + + + Remove-AzureRmAvailabilitySet + + Removes an availability set from Azure. + + + + + Remove + AzureRmAvailabilitySet + + + + The Remove-AzureRmAvailabilitySet cmdlet removes an availability set from Azure. + + + + Remove-AzureRmAvailabilitySet + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + Name + + Specifies the name of the availability set to remove. + + String + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + Name + + Specifies the name of the availability set to remove. + + String + + String + + + none + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + SwitchParameter + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Remove an availability set -------------------------- + + PS C:\> + + PS C:\>Remove-AzureRmAvailabilitySet -Name "AvailabilitySet03" -ResourceGroupName "ResourceGroup11" + + This command removes an availability set named AvailablitySet03 in the resource group named ResourceGroup11. + + + + + + + + + + + + + + + + Get-AzureRmAvailabilitySet + + + + New-AzureRmAvailabilitySet + + + + + + + + Remove-AzureRmVM + + Removes a virtual machine from Azure. + + + + + Remove + AzureRmVM + + + + The Remove-AzureRmVM cmdlet removes a virtual machine from Azure. + + + + Remove-AzureRmVM + + Name + + Specifies the name of the virtual machine to remove. + + String + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Remove-AzureRmVM + + Name + + Specifies the name of the virtual machine to remove. + + String + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + + Id + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Name + + Specifies the name of the virtual machine to remove. + + String + + String + + + none + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + SwitchParameter + + + none + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Id + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Remove a virtual machine -------------------------- + + PS C:\> + + PS C:\>Remove-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" + + This command removes the virtual machine named VirtualMachine07 in the resource group ResourceGroup11. + + + + + + + + + + + + + + + + Get-AzureRmVM + + + + New-AzureRmVM + + + + Restart-AzureRmVM + + + + Start-AzureRmVM + + + + Stop-AzureRmVM + + + + Update-AzureRmVM + + + + + + + + Remove-AzureRmVMAccessExtension + + Removes the VMAccess extension from a virtual machine. + + + + + Remove + AzureRmVMAccessExtension + + + + The Remove-AzureRmVMAccessExtension cmdlet removes the Virtual Machine Access (VMAccess) Virtual Machine Extension from a virtual machine. + + + + Remove-AzureRmVMAccessExtension + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + + VMName + + Specifies the name of a virtual machine. This cmdlet removes VMAccess for the virtual machine that this parameter specifies. + + String + + + Name + + Specifies the name of the extension that this cmdlet removes. + + String + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + String + + + none + + + VMName + + Specifies the name of a virtual machine. This cmdlet removes VMAccess for the virtual machine that this parameter specifies. + + String + + String + + + none + + + Name + + Specifies the name of the extension that this cmdlet removes. + + String + + String + + + none + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + SwitchParameter + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- 1: -------------------------- + + PS C:\> + + + + + + + + + + + + + + + + + + + + Get-AzureRmVMAccessExtension + + + + Set-AzureRmVMAccessExtension + + + + Remove-AzureRmVMExtension + + + + + + + + Remove-AzureRmVMBackup + + Remove-AzureRmVMBackup cmdlet remove the VM Backup for the VM. + + + + + Remove + AzureRmVMBackup + + + + + + + + Remove-AzureRmVMBackup + + ResourceGroupName + + Resource group name of the virtual machine + + String + + + VMName + + Name of the virtual machine + + String + + + Tag + + The tag for the VM Backup. This is used for identify the backups. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Resource group name of the virtual machine + + String + + String + + + + + + VMName + + Name of the virtual machine + + String + + String + + + + + + Tag + + The tag for the VM Backup. This is used for identify the backups. + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Remove-AzureRmVMCustomScriptExtension + + Removes a custom script extension from a virtual machine. + + + + + Remove + AzureRmVMCustomScriptExtension + + + + The Remove-AzureRmVMCustomScriptExtension cmdlet removes a custom script Virtual Machine Extension from a virtual machine. + + + + Remove-AzureRmVMCustomScriptExtension + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + + VMName + + Specifies the name of a virtual machine from which this cmdlet removes the custom script extension. + + String + + + Name + + Specifies the name of the custom script extension that this cmdlet removes. + + String + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + String + + + none + + + VMName + + Specifies the name of a virtual machine from which this cmdlet removes the custom script extension. + + String + + String + + + none + + + Name + + Specifies the name of the custom script extension that this cmdlet removes. + + String + + String + + + none + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + SwitchParameter + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- 1: -------------------------- + + PS C:\> + + + + + + + + + + + + + + + + + + + + Get-AzureRmVMCustomScriptExtension + + + + Set-AzureRmVMCustomScriptExtension + + + + + + + + Remove-AzureRmVMDataDisk + + Removes a data disk from a virtual machine. + + + + + Remove + AzureRmVMDataDisk + + + + The Remove-AzureRmVMDataDisk cmdlet removes a data disk from a virtual machine. + + + + Remove-AzureRmVMDataDisk + + VM + + Specifies the local virtual machine object from which to remove a data disk. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + + DataDiskNames + + + + String[] + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + Specifies the local virtual machine object from which to remove a data disk. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + DataDiskNames + + + + String[] + + String[] + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Name + + Specifies the name of the data disk to add. + + string + + string + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Remove a data disk from a virtual machine -------------------------- + + PS C:\> + + PS C:\>$VirtualMachine = Get-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" +PS C:\> Remove-AzureRmVMDataDisk -VM $VirtualMachine -Name "disk3" +PS C:\> Update-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" -VM $VirtualMachine + + The first command gets the virtual machine named VirtualMachine07 by using the Get-AzureRmVM cmdlet. The command stores the virtual machine in the $VirtualMachine variable. + + + + + + + + + + + + + + + + Add-AzureRmVMDataDisk + + + + Get-AzureRmVM + + + + + + + + Remove-AzureRmVMDiagnosticsExtension + + + + + + + Remove + AzureRmVMDiagnosticsExtension + + + + + + + + Remove-AzureRmVMDiagnosticsExtension + + ResourceGroupName + + + + String + + + VMName + + + + String + + + Name + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + + + String + + String + + + + + + VMName + + + + String + + String + + + + + + Name + + + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Remove-AzureRmVMDiskEncryptionExtension + + Remove-AzureRmVMDiskEncryptionExtension cmdlet deletes disk encryption extension from the VM. If no extension name is specified, this cmdlet removes extension with default name 'AzureDiskEncryption' for Windows VMs and 'AzureDiskEncryptionForLinux' for Linux VMs. + + + + + Remove + AzureRmVMDiskEncryptionExtension + + + + + + + + Remove-AzureRmVMDiskEncryptionExtension + + ResourceGroupName + + Resource group name of the virtual machine + + String + + + VMName + + Name of the virtual machine + + String + + + Name + + Name of the ARM resource that represents the extension. The Set-AzureRmVMDiskEncryptionExtension cmdlet sets this name to 'AzureDiskEncryption' for Windows VMs and 'AzureDiskEncryptionForLinux' for Linux VMs. Which is the same as the default value used by Remove-AzureRmVMAzureDiskEncryptionExtension. Specify this parameter only if you changed the default name in the Set cmdlet or used a different resource name in an ARM template + + String + + + Force + + Force switch removes the extension without prompting for a confirmation + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Resource group name of the virtual machine + + String + + String + + + + + + VMName + + Name of the virtual machine + + String + + String + + + + + + Name + + Name of the ARM resource that represents the extension. The Set-AzureRmVMDiskEncryptionExtension cmdlet sets this name to 'AzureDiskEncryption' for Windows VMs and 'AzureDiskEncryptionForLinux' for Linux VMs. Which is the same as the default value used by Remove-AzureRmVMAzureDiskEncryptionExtension. Specify this parameter only if you changed the default name in the Set cmdlet or used a different resource name in an ARM template + + String + + String + + + + + + Force + + Force switch removes the extension without prompting for a confirmation + + SwitchParameter + + SwitchParameter + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + + PS C:\> + + $rgName = 'MyResourceGroup'; +$vmName = 'MyWindowsVM'; +Remove-AzureRmVMDiskEncryptionExtension -ResourceGroupName $rgname -VMName $vmName; + + + + + + + + + + + + + + + + -------------------------- Example 2 -------------------------- + + PS C:\> + + $rgName = 'MyResourceGroup'; +$vmName = 'MyWindowsVM'; +$extensionNmae = 'MyDiskEncryptionExtension' +Remove-AzureRmVMDiskEncryptionExtension -ResourceGroupName $rgname -VMName $vmName -Name $extensionNmae; + + + + + + + + + + + + + + + + + + + + + + Remove-AzureRmVMDscExtension + + Removes DSC extension handler from a VM in a resource group + + + + + Remove + AzureRmVMDscExtension + + + + Removes DSC extension handler from a VM in a resource group + + + + Remove-AzureRmVMDscExtension + + ResourceGroupName + + The name of the resource group + + String + + + VMName + + The name of the virtual machine + + String + + + Name + + Name of the ARM resource that represents the extension. The Set-AzureRmVMDscExtension cmdlet sets this name to 'Microsoft.Powershell.DSC', which is the same value used by Remove-AzureRmVMDscExtension. Specify this parameter only if you changed the default name in the Set cmdlet or used a different resource name in an ARM template + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + WhatIf + + + + SwitchParameter + + + Confirm + + + + SwitchParameter + + + + + + ResourceGroupName + + The name of the resource group + + String + + String + + + + + + VMName + + The name of the virtual machine + + String + + String + + + + + + Name + + Name of the ARM resource that represents the extension. The Set-AzureRmVMDscExtension cmdlet sets this name to 'Microsoft.Powershell.DSC', which is the same value used by Remove-AzureRmVMDscExtension. Specify this parameter only if you changed the default name in the Set cmdlet or used a different resource name in an ARM template + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + WhatIf + + + + SwitchParameter + + SwitchParameter + + + + + + Confirm + + + + SwitchParameter + + SwitchParameter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1 -------------------------- + + PS C:\> + + PS C:\> Remove-AzureRmVMDscExtension –ResouceGroupName Name -VMName VM -Name DSC + + Description + + + + + + + + + + + + + + + + + + + + Remove-AzureRmVMExtension + + Removes an extension from a virtual machine. + + + + + Remove + AzureRmVMExtension + + + + The Remove-AzureRmVMExtension cmdlet removes an extension from the Virtual Machine Extensions of a virtual machine. + + + + Remove-AzureRmVMExtension + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + VMName + + Specifies the name of a virtual machine. This cmdlet removes extensions from the virtual machine that this parameter specifies. + + String + + + Name + + Specifies the name of the extension to remove. + + String + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + VMName + + Specifies the name of a virtual machine. This cmdlet removes extensions from the virtual machine that this parameter specifies. + + String + + String + + + none + + + Name + + Specifies the name of the extension to remove. + + String + + String + + + none + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + SwitchParameter + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Remove an extension from a virtual machine -------------------------- + + PS C:\> + + PS C:\>Remove-AzureRmVMExtension -ResourceGroupName "ResourceGroup11" -Name "ContosoTest" -VMName "VirtualMachine22" + + This command removes the extension named ContosoTest from the virtual machine named VirtualMachine22 in ResourceGroup11. + + + + + + + + + + + + + + + + Get-AzureRmVMExtension + + + + Set-AzureRmVMExtension + + + + + + + + Remove-AzureRmVMNetworkInterface + + Removes a network interface from a virtual machine. + + + + + Remove + AzureRmVMNetworkInterface + + + + The Remove-AzureRmVMNetworkInterface cmdlet removes a network interface from a virtual machine. + + + + Remove-AzureRmVMNetworkInterface + + VM + + Specifies the virtual machine from which this cmdlet removes a network interface. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + + NetworkInterfaceIDs + + + + String[] + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + Specifies the virtual machine from which this cmdlet removes a network interface. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + NetworkInterfaceIDs + + + + String[] + + String[] + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Id + + Specifies the ID of the network interface that this cmdlet removes from the virtual machine. + + string + + string + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- 1: -------------------------- + + PS C:\> + + + + + + + + + + + + + + + + + + + + Get-AzureRmVM + + + + + + + + Remove-AzureRmVMSqlServerExtension + + + + + + + Remove + AzureRmVMSqlServerExtension + + + + + + + + Remove-AzureRmVMSqlServerExtension + + ResourceGroupName + + + + String + + + VMName + + + + String + + + Name + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + + + String + + String + + + + + + VMName + + + + String + + String + + + + + + Name + + + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Restart-AzureRmVM + + Restarts an Azure virtual machine. + + + + + Restart + AzureRmVM + + + + The Restart-AzureRmVM cmdlet restarts an Azure virtual machine. + + + + Restart-AzureRmVM + + Name + + Specifies the name of the virtual machine to restart. + + String + + + ResourceGroupName + + Specifies the name of the resource group. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Restart-AzureRmVM + + Name + + Specifies the name of the virtual machine to restart. + + String + + + Id + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Name + + Specifies the name of the virtual machine to restart. + + String + + String + + + none + + + ResourceGroupName + + Specifies the name of the resource group. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Id + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Restart a virtual machine -------------------------- + + PS C:\> + + PS C:\>Restart-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" + + This command restarts the virtual machine named VirtualMachine07 in ResourceGroup11. + + + + + + + + + + + + + + + + Get-AzureRmVM + + + + New-AzureRmVM + + + + Remove-AzureRmVM + + + + Start-AzureRmVM + + + + Stop-AzureRmVM + + + + Update-AzureRmVM + + + + + + + + Save-AzureRmVhd + + + + + + + Save + AzureRmVhd + + + + + + + + Save-AzureRmVhd + + ResourceGroupName + + + + String + + + SourceUri + + + + Uri + + + LocalFilePath + + + + FileInfo + + + NumberOfThreads + + + + Int32 + + + OverWrite + + + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Save-AzureRmVhd + + StorageKey + + + + String + + + SourceUri + + + + Uri + + + LocalFilePath + + + + FileInfo + + + NumberOfThreads + + + + Int32 + + + OverWrite + + + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + + + String + + String + + + + + + SourceUri + + + + Uri + + Uri + + + + + + LocalFilePath + + + + FileInfo + + FileInfo + + + + + + NumberOfThreads + + + + Int32 + + Int32 + + + + + + OverWrite + + + + SwitchParameter + + SwitchParameter + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + StorageKey + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Save-AzureRmVMImage + + Captures a virtual machine as a VMImage. + + + + + Save + AzureRmVMImage + + + + The Save-AzureRmVMImage cmdlet captures a virtual machine as a VMImage. Before you create a virtual machine image, sysprep the virtual machine, and then mark it as generalized by using the Set-AzureRmVM cmdlet. + The output of this cmdlet is a JavaScript Object Notation (JSON) template. You can deploy virtual machines from your captured image. + + + + Save-AzureRmVMImage + + Name + + + + String + + + DestinationContainerName + + Specifies the name of a container. The virtual hard disks (VHDs) that constitute the VMImage reside in the container that this parameter specifies. If the VHDs are spread across multiple storage accounts, this cmdlet creates one container that has this name in each storage account. + + String + + + VHDNamePrefix + + Specifies the prefix in the name of the blobs that constitute the storage profile of the VMImage. For example, a prefix vhdPrefix for operating system disk results in the name vhdPrefix-osdisk. + + String + + + Overwrite + + Indicates that this cmdlet overwrites any VHDs that have the same prefix in the destination container. + + SwitchParameter + + + Path + + + + String + + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Save-AzureRmVMImage + + Name + + + + String + + + DestinationContainerName + + Specifies the name of a container. The virtual hard disks (VHDs) that constitute the VMImage reside in the container that this parameter specifies. If the VHDs are spread across multiple storage accounts, this cmdlet creates one container that has this name in each storage account. + + String + + + VHDNamePrefix + + Specifies the prefix in the name of the blobs that constitute the storage profile of the VMImage. For example, a prefix vhdPrefix for operating system disk results in the name vhdPrefix-osdisk. + + String + + + Overwrite + + Indicates that this cmdlet overwrites any VHDs that have the same prefix in the destination container. + + SwitchParameter + + + Path + + + + String + + + Id + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Name + + + + String + + String + + + + + + DestinationContainerName + + Specifies the name of a container. The virtual hard disks (VHDs) that constitute the VMImage reside in the container that this parameter specifies. If the VHDs are spread across multiple storage accounts, this cmdlet creates one container that has this name in each storage account. + + String + + String + + + none + + + VHDNamePrefix + + Specifies the prefix in the name of the blobs that constitute the storage profile of the VMImage. For example, a prefix vhdPrefix for operating system disk results in the name vhdPrefix-osdisk. + + String + + String + + + none + + + Overwrite + + Indicates that this cmdlet overwrites any VHDs that have the same prefix in the destination container. + + SwitchParameter + + SwitchParameter + + + none + + + Path + + + + String + + String + + + + + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Id + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + VMName + + Specifies the name of the virtual machine that this cmdlet saves. + + string + + string + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Capture a virtual machine -------------------------- + + PS C:\> + + PS C:\>Set-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" -Generalized +PS C:\> Save-AzureRmVMImage -ResourceGroupName "ResourceGroup11" -VMName "VirtualMachine07" -DestinationContainerName "VMContainer01" -VHDNamePrefix "VM07" + + The first marks the virtual machine named VirtualMachine07 as generalized. + + + + + + + + + + + + + + + + Get-AzureRmVMImage + + + + Get-AzureRmVMImageOffer + + + + Get-AzureRmVMImagePublisher + + + + Get-AzureRmVMImageSku + + + + Set-AzureRmVM + + + + + + + + Set-AzureRmVM + + Marks a virtual machine as generalized. + + + + + Set + AzureRmVM + + + + The Set-AzureRmVM cmdlet marks a virtual machine as generalized. Before you run this cmdlet, log on to the virtual machine and use Sysprep to prepare the hard disk. + + + + Set-AzureRmVM + + Name + + Specifies the name of the virtual machine on which this cmdlet operates. + + String + + + Generalized + + Indicates that this cmdlet marks a virtual machine as generalized. + + SwitchParameter + + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Set-AzureRmVM + + Name + + Specifies the name of the virtual machine on which this cmdlet operates. + + String + + + Generalized + + Indicates that this cmdlet marks a virtual machine as generalized. + + SwitchParameter + + + Id + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Name + + Specifies the name of the virtual machine on which this cmdlet operates. + + String + + String + + + none + + + Generalized + + Indicates that this cmdlet marks a virtual machine as generalized. + + SwitchParameter + + SwitchParameter + + + none + + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Id + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Mark a virtual machine as generalized -------------------------- + + PS C:\> + + PS C:\>Set-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" -Generalized + + This command marks the virtual machine named VirtualMachine07 as generalized. + + + + + + + + + + + + + + + + Get-AzureRmVM + + + + + + + + Set-AzureRmVMAccessExtension + + Adds the VMAccess extension to a virtual machine. + + + + + Set + AzureRmVMAccessExtension + + + + The Set-AzureRmVMAccessExtension cmdlet adds the Virtual Machine Access (VMAccess) Virtual Machine Extension to a virtual machine. VMAccess can reset the virtual machine user name and password. + + + + Set-AzureRmVMAccessExtension + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + + VMName + + Specifies the name of a virtual machine. This cmdlet adds VMAccess for the virtual machine that this parameter specifies. + + String + + + Name + + Specifies the name of the extension that this cmdlet adds. + + String + + + TypeHandlerVersion + + Specifies the version of the extension to use for this virtual machine. To obtain the version, run the Get-AzureRmVMExtensionImage cmdlet with a value of Microsoft.Compute for the PublisherName parameter and VMAccessAgent for the Type parameter. + + String + + + UserName + + Specifies the new user name for the virtual machine. + + String + + + Password + + Specifies the new password of the virtual machine. + + String + + + Location + + Specifies the location of the virtual machine. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + String + + + none + + + VMName + + Specifies the name of a virtual machine. This cmdlet adds VMAccess for the virtual machine that this parameter specifies. + + String + + String + + + none + + + Name + + Specifies the name of the extension that this cmdlet adds. + + String + + String + + + none + + + TypeHandlerVersion + + Specifies the version of the extension to use for this virtual machine. To obtain the version, run the Get-AzureRmVMExtensionImage cmdlet with a value of Microsoft.Compute for the PublisherName parameter and VMAccessAgent for the Type parameter. + + String + + String + + + none + + + UserName + + Specifies the new user name for the virtual machine. + + String + + String + + + none + + + Password + + Specifies the new password of the virtual machine. + + String + + String + + + none + + + Location + + Specifies the location of the virtual machine. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Add a VMAccess extension -------------------------- + + PS C:\> + + PS C:\> Set-AzureRmVMAccessExtension -ResourceGroupName "ResrouceGroup11" -Location "Central US" -VMName "VirtualMachine07" -Name "ContosoTest" -TypeHandlerVersion "2.0" -UserName "PFuller" -Password "Password" + + This command adds a VMAccess extension for the virtual machine named VirtualMachine07 in ResrouceGroup11. The command specifies the name and type handler version for VMAccess. + + + + + + + + + + + + + + + + Get-AzureRmVMAccessExtension + + + + Remove-AzureRmVMAccessExtension + + + + Set-AzureRmVMExtension + + + + Get-AzureRmVMExtensionImage + + + + + + + + Set-AzureRmVMBackupExtension + + Set-AzureRmVMBackupExtension cmdlet create a backup for this VM. + + + + + Set + AzureRmVMBackupExtension + + + + + + + + Set-AzureRmVMBackupExtension + + ResourceGroupName + + Resource group name of the virtual machine + + String + + + VMName + + Name of the virtual machine + + String + + + Name + + Name of the ARM resource that represents the extension. This is 'VMBackupForLinuxExtension' for Linux VMs. + + String + + + Tag + + The tag for the VM Backup. This is used for identify the backups. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Resource group name of the virtual machine + + String + + String + + + + + + VMName + + Name of the virtual machine + + String + + String + + + + + + Name + + Name of the ARM resource that represents the extension. This is 'VMBackupForLinuxExtension' for Linux VMs. + + String + + String + + + + + + Tag + + The tag for the VM Backup. This is used for identify the backups. + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Set-AzureRmVMBootDiagnostics + + + + + + + Set + AzureRmVMBootDiagnostics + + + + + + + + Set-AzureRmVMBootDiagnostics + + VM + + + + PSVirtualMachine + + + Enable + + + + SwitchParameter + + + ResourceGroupName + + + + String + + + StorageAccountName + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Set-AzureRmVMBootDiagnostics + + VM + + + + PSVirtualMachine + + + Disable + + + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + + + PSVirtualMachine + + PSVirtualMachine + + + + + + Enable + + + + SwitchParameter + + SwitchParameter + + + + + + ResourceGroupName + + + + String + + String + + + + + + StorageAccountName + + + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Disable + + + + SwitchParameter + + SwitchParameter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Set-AzureRmVMCustomScriptExtension + + Adds a custom script extension to a virtual machine. + + + + + Set + AzureRmVMCustomScriptExtension + + + + The Set-AzureRmVMCustomScriptExtension cmdlet adds a custom script Virtual Machine Extension to a virtual machine. This extension allows you to run your own scripts on the virtual machine. + + + + Set-AzureRmVMCustomScriptExtension + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + + VMName + + Specifies the name of a virtual machine. This cmdlet adds the custom script extension for the virtual machine that this parameter specifies. + + String + + + Name + + Specifies the name of the custom script extension. + + String + + + TypeHandlerVersion + + Specifies the version of the extension to use for this virtual machine. To obtain the version, run the Get-AzureRmVMExtensionImage cmdlet with a value of Microsoft.Compute for the PublisherName parameter and VMAccessAgent for the Type parameter. + + String + + + ContainerName + + Specifies the name of the Azure Storage container where this cmdlet stores the script. + + String + + + FileName + + Specifies the name of the script file. + + String[] + + + StorageAccountName + + Specifies the name of the Azure Storage account where this cmdlet stores the script. + + String + + + StorageEndpointSuffix + + Specifies the storage endpoint suffix. + + String + + + StorageAccountKey + + Specifies the key for the Azure Storage container. + + String + + + Run + + Specifies the command to use that runs your script. + + String + + + Argument + + Specifies arguments that the script extension passes to the script. + + String + + + Location + + Specifies the location of the virtual machine. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Set-AzureRmVMCustomScriptExtension + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + + VMName + + Specifies the name of a virtual machine. This cmdlet adds the custom script extension for the virtual machine that this parameter specifies. + + String + + + Name + + Specifies the name of the custom script extension. + + String + + + TypeHandlerVersion + + Specifies the version of the extension to use for this virtual machine. To obtain the version, run the Get-AzureRmVMExtensionImage cmdlet with a value of Microsoft.Compute for the PublisherName parameter and VMAccessAgent for the Type parameter. + + String + + + FileUri + + Specifies the URI of the script file. + + String[] + + + Run + + Specifies the command to use that runs your script. + + String + + + Argument + + Specifies arguments that the script extension passes to the script. + + String + + + Location + + Specifies the location of the virtual machine. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of the resource group of the virtual machine. + + String + + String + + + none + + + VMName + + Specifies the name of a virtual machine. This cmdlet adds the custom script extension for the virtual machine that this parameter specifies. + + String + + String + + + none + + + Name + + Specifies the name of the custom script extension. + + String + + String + + + none + + + TypeHandlerVersion + + Specifies the version of the extension to use for this virtual machine. To obtain the version, run the Get-AzureRmVMExtensionImage cmdlet with a value of Microsoft.Compute for the PublisherName parameter and VMAccessAgent for the Type parameter. + + String + + String + + + none + + + ContainerName + + Specifies the name of the Azure Storage container where this cmdlet stores the script. + + String + + String + + + none + + + FileName + + Specifies the name of the script file. + + String[] + + String[] + + + none + + + StorageAccountName + + Specifies the name of the Azure Storage account where this cmdlet stores the script. + + String + + String + + + none + + + StorageEndpointSuffix + + Specifies the storage endpoint suffix. + + String + + String + + + none + + + StorageAccountKey + + Specifies the key for the Azure Storage container. + + String + + String + + + none + + + Run + + Specifies the command to use that runs your script. + + String + + String + + + none + + + Argument + + Specifies arguments that the script extension passes to the script. + + String + + String + + + none + + + Location + + Specifies the location of the virtual machine. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + FileUri + + Specifies the URI of the script file. + + String[] + + String[] + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Add a custom script -------------------------- + + PS C:\> + + PS C:\>Set-AzureRmVMCustomScriptExtension -ResourceGroupName "ResourceGroup11" -Location "Central US" -VMName "VirtualMachine07" -Name "contosotest" -TypeHandlerVersion "1.1" -StorageAccountName "contoso" -StorageAccountKey <StorageKey> -FileName "contososcript.exe" -ContainerName "scripts" + + This command adds a custom script to the virtual machine named VirtualMachine07. The script file is contososcript.exe. + + + + + + + + + + + + + + + + Get-AzureRmVMCustomScriptExtension + + + + Remove-AzureRmVMCustomScriptExtension + + + + + + + + Set-AzureRmVMDataDisk + + + + + + + Set + AzureRmVMDataDisk + + + + + + + + Set-AzureRmVMDataDisk + + VM + + + + PSVirtualMachine + + + Name + + + + String + + + Caching + + + + String + + + DiskSizeInGB + + + + Nullable`1[Int32] + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Set-AzureRmVMDataDisk + + VM + + + + PSVirtualMachine + + + Lun + + + + Nullable`1[Int32] + + + Caching + + + + String + + + DiskSizeInGB + + + + Nullable`1[Int32] + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + + + PSVirtualMachine + + PSVirtualMachine + + + + + + Name + + + + String + + String + + + + + + Caching + + + + String + + String + + + + + + DiskSizeInGB + + + + Nullable`1[Int32] + + Nullable`1[Int32] + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Lun + + + + Nullable`1[Int32] + + Nullable`1[Int32] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Set-AzureRmVMDiagnosticsExtension + + + + + + + Set + AzureRmVMDiagnosticsExtension + + + + + + + + Set-AzureRmVMDiagnosticsExtension + + ResourceGroupName + + + + String + + + VMName + + + + String + + + DiagnosticsConfigurationPath + + + + String + + + StorageContext + + + + AzureStorageContext + + + Location + + + + String + + + Name + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + + + String + + String + + + + + + VMName + + + + String + + String + + + + + + DiagnosticsConfigurationPath + + + + String + + String + + + + + + StorageContext + + + + AzureStorageContext + + AzureStorageContext + + + + + + Location + + + + String + + String + + + + + + Name + + + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Set-AzureRmVMDiskEncryptionExtension + + Set-AzureRmVMDiskEncryptionExtension cmdlet enables encryption on a running IaaS VM in Azure. This cmdlet prepares the VM to enable encryption, which may need rebooting the VM when done for the first time. This cmdlet installs an extension on the VM to enable encryption. If no Name parameter is specified, an extension with default name 'AzureDiskEncryption' for Windows VMs and 'AzureDiskEncryptionForLinux' for Linux VMs is created. Please save your work on the VM before running this cmdlet and wait for it to be done. + + + + + Set + AzureRmVMDiskEncryptionExtension + + + + + + + + Set-AzureRmVMDiskEncryptionExtension + + ResourceGroupName + + Resource group name of the virtual machine + + String + + + VMName + + Name of the virtual machine + + String + + + AadClientID + + Client ID of the Azure Active Directory application that has permissions to write secrets to KeyVault + + String + + + AadClientSecret + + Client secret of the Azure Active Directory application that has permissions to write secrets to KeyVault + + String + + + DiskEncryptionKeyVaultUrl + + KeyVault URL to which the VM encryption keys should be uploaded to. + + String + + + DiskEncryptionKeyVaultId + + Resource ID of the KeyVault to which the VM encryption keys should be uploaded to. + + String + + + KeyEncryptionKeyUrl + + URL of the key encryption key that is used to wrap and unwrap the VM encryption key. This must be the full versioned URL. See examples for more details. + + String + + + KeyEncryptionKeyVaultId + + Resource ID of the KeyVault containing key encryption key that is used to wrap and unwrap the VM encryption key. This must be the full versioned URL. See examples for more details. + + String + + + KeyEncryptionAlgorithm + + Algorithm used to wrap and unwrap the VM encryption key with key encryption key. Default value is RSA-OAEP if not specified. + + String + + + VolumeType + + Type of VM volumes to perform the encryption operation. For Windows VMs allowed values are All, OS and Data . For Linux VMs allowed value is Data only. Default for Windows VMs is All if not specified. + + String + + + SequenceVersion + + Sequence number of the encryption operations on a given VM. This should be unique per each encryption operation performed on the same VM. See examples on how to retrieve the previous sequence number supplied. + + String + + + TypeHandlerVersion + + Version of the encryption extension. By default the latest version of the extension is used if not provided. + + String + + + Name + + Name of the ARM resource that represents the extension. This is defaulted to 'AzureDiskEncryption' for Windows VMs and 'AzureDiskEncryptionForLinux' for Linux VMs. + + String + + + Passphrase + + Passphrase specified in the powershell. This parameter only works for Linux VM. + + String + + + Force + + Force switch performs the encryption operation without prompting for a confirmation + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Set-AzureRmVMDiskEncryptionExtension + + ResourceGroupName + + Resource group name of the virtual machine + + String + + + VMName + + Name of the virtual machine + + String + + + AadClientID + + Client ID of the Azure Active Directory application that has permissions to write secrets to KeyVault + + String + + + AadClientCertThumbprint + + Thumbprint of the Azure Active Directory application client certificate that has permissions to write secrets to KeyVault. The certificate must be previously deployed on to the VM local machine My certificate store. + + String + + + DiskEncryptionKeyVaultUrl + + KeyVault URL to which the VM encryption keys should be uploaded to. + + String + + + DiskEncryptionKeyVaultId + + Resource ID of the KeyVault to which the VM encryption keys should be uploaded to. + + String + + + KeyEncryptionKeyUrl + + URL of the key encryption key that is used to wrap and unwrap the VM encryption key. This must be the full versioned URL. See examples for more details. + + String + + + KeyEncryptionKeyVaultId + + Resource ID of the KeyVault containing key encryption key that is used to wrap and unwrap the VM encryption key. This must be the full versioned URL. See examples for more details. + + String + + + KeyEncryptionAlgorithm + + Algorithm used to wrap and unwrap the VM encryption key with key encryption key. Default value is RSA-OAEP if not specified. + + String + + + VolumeType + + Type of VM volumes to perform the encryption operation. For Windows VMs allowed values are All, OS and Data . For Linux VMs allowed value is Data only. Default for Windows VMs is All if not specified. + + String + + + SequenceVersion + + Sequence number of the encryption operations on a given VM. This should be unique per each encryption operation performed on the same VM. See examples on how to retrieve the previous sequence number supplied. + + String + + + TypeHandlerVersion + + Version of the encryption extension. By default the latest version of the extension is used if not provided. + + String + + + Name + + Name of the ARM resource that represents the extension. This is defaulted to 'AzureDiskEncryption' for Windows VMs and 'AzureDiskEncryptionForLinux' for Linux VMs. + + String + + + Passphrase + + Passphrase specified in the powershell. This parameter only works for Linux VM. + + String + + + Force + + Force switch performs the encryption operation without prompting for a confirmation + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Resource group name of the virtual machine + + String + + String + + + + + + VMName + + Name of the virtual machine + + String + + String + + + + + + AadClientID + + Client ID of the Azure Active Directory application that has permissions to write secrets to KeyVault + + String + + String + + + + + + AadClientSecret + + Client secret of the Azure Active Directory application that has permissions to write secrets to KeyVault + + String + + String + + + + + + DiskEncryptionKeyVaultUrl + + KeyVault URL to which the VM encryption keys should be uploaded to. + + String + + String + + + + + + DiskEncryptionKeyVaultId + + Resource ID of the KeyVault to which the VM encryption keys should be uploaded to. + + String + + String + + + + + + KeyEncryptionKeyUrl + + URL of the key encryption key that is used to wrap and unwrap the VM encryption key. This must be the full versioned URL. See examples for more details. + + String + + String + + + + + + KeyEncryptionKeyVaultId + + Resource ID of the KeyVault containing key encryption key that is used to wrap and unwrap the VM encryption key. This must be the full versioned URL. See examples for more details. + + String + + String + + + + + + KeyEncryptionAlgorithm + + Algorithm used to wrap and unwrap the VM encryption key with key encryption key. Default value is RSA-OAEP if not specified. + + String + + String + + + + + + VolumeType + + Type of VM volumes to perform the encryption operation. For Windows VMs allowed values are All, OS and Data . For Linux VMs allowed value is Data only. Default for Windows VMs is All if not specified. + + String + + String + + + + + + SequenceVersion + + Sequence number of the encryption operations on a given VM. This should be unique per each encryption operation performed on the same VM. See examples on how to retrieve the previous sequence number supplied. + + String + + String + + + + + + TypeHandlerVersion + + Version of the encryption extension. By default the latest version of the extension is used if not provided. + + String + + String + + + + + + Name + + Name of the ARM resource that represents the extension. This is defaulted to 'AzureDiskEncryption' for Windows VMs and 'AzureDiskEncryptionForLinux' for Linux VMs. + + String + + String + + + + + + Passphrase + + Passphrase specified in the powershell. This parameter only works for Linux VM. + + String + + String + + + + + + Force + + Force switch performs the encryption operation without prompting for a confirmation + + SwitchParameter + + SwitchParameter + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + AadClientCertThumbprint + + Thumbprint of the Azure Active Directory application client certificate that has permissions to write secrets to KeyVault. The certificate must be previously deployed on to the VM local machine My certificate store. + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -------------------------- Enabling encryption using AAD Client ID, Client Secret -------------------------- + + PS C:\> + + $rgName = 'MyResourceGroup'; +$vmName = 'MyWindowsVM'; + +$aadClientID = "<clientID of your AAD app>"; +$aadClientSecret = "<clientSecret of your AAD app>"; + +$vaultName= 'MyKeyVault'; +$keyVault = Get-AzureRmKeyVault -VaultName $vaultName -ResourceGroupName $rgname; +$diskEncryptionKeyVaultUrl = $keyVault.VaultUri; +$keyVaultResourceId = $keyVault.ResourceId; + +Set-AzureRmVMDiskEncryptionExtension -ResourceGroupName $rgname -VMName $vmName -AadClientID $aadClientID -AadClientSecret $aadClientSecret -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl -DiskEncryptionKeyVaultId $keyVaultResourceId ; + + + + + + + + + + + + + + + + -------------------------- Enabling encryption using AAD Client ID, client cert thumbprint -------------------------- + + PS C:\> + + $rgName = 'MyResourceGroup'; +$vmName = 'MyWindowsVM'; + +#The KeyVault must have enabledForDiskEncryption property set on it +$vaultName= 'MyKeyVault'; +$keyVault = Get-AzureRmKeyVault -VaultName $vaultName -ResourceGroupName $rgname; +$diskEncryptionKeyVaultUrl = $keyVault.VaultUri; +$keyVaultResourceId = $keyVault.ResourceId; + +# create AAD application and associate the certificate +$certPath = 'C:\certificates\examplecert.pfx'; +$certPassword = 'yourPassword'; +$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certPath, $certPassword); +$keyValue = [System.Convert]::ToBase64String($cert.GetRawCertData()); +$azureAdApplication = New-AzureRmADApplication -DisplayName "<Your Application Display Name>" -HomePage "<https://YourApplicationHomePage>" -IdentifierUris "<https://YouApplicationUri>" -KeyValue $keyValue -KeyType AsymmetricX509Cert ; +$servicePrincipal = New-AzureRmADServicePrincipal –ApplicationId $azureAdApplication.ApplicationId; + +$aadClientID = $azureAdApplication.ApplicationId; +$aadClientCertThumbprint= $cert.Thumbprint; + +#Upload pfx to KeyVault +$keyVaultSecretName = 'myaadcert'; +$fileContentBytes = get-content $certPath -Encoding Byte; +$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes); +$jsonObject = @" { "data": "$filecontentencoded", "dataType" :"pfx", "password": "$certPassword" } "@ ; +$jsonObjectBytes = [System.Text.Encoding]::UTF8.GetBytes($jsonObject); +$jsonEncoded = [System.Convert]::ToBase64String($jsonObjectBytes); + +$secret = ConvertTo-SecureString -String $jsonEncoded -AsPlainText -Force; +Set-AzureKeyVaultSecret -VaultName $vaultName-Name $keyVaultSecretName -SecretValue $secret; +Set-AzureRmKeyVaultAccessPolicy -VaultName $vaultName -ResourceGroupName $rgName –EnabledForDeployment; + +#deploy cert to VM +$certUrl = (Get-AzureKeyVaultSecret -VaultName $vaultName -Name $keyVaultSecretName).Id +$sourceVaultId = (Get-AzureRmKeyVault -VaultName $vaultName -ResourceGroupName $rgName).ResourceId +$vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName +$vm = Add-AzureRmVMSecret -VM $vm -SourceVaultId $sourceVaultId -CertificateStore "My" -CertificateUrl $certUrl +Update-AzureRmVM -VM $vm -ResourceGroupName $rgName + +#Enable encryption on the VM using AAD client ID and client cert thumbprint +Set-AzureRmVMDiskEncryptionExtension -ResourceGroupName $rgname -VMName $vmName -AadClientID $aadClientID -AadClientCertThumbprint $aadClientCertThumbprint -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl -DiskEncryptionKeyVaultId $keyVaultResourceId ; + + + + + + + + + + + + + + + + -------------------------- Enable encryption using AAD ClientID, Client Secret and wrap diskEncryptionKey with KeyEncryptionKey -------------------------- + + PS C:\> + + $rgName = 'MyResourceGroup'; +$vmName = 'MyWindowsVM'; + +$aadClientID = "<clientID of your AAD app>"; +$aadClientSecret = "<clientSecret of your AAD app>"; + +$vaultName= 'MyKeyVault'; +$keyVault = Get-AzureRmKeyVault -VaultName $vaultName -ResourceGroupName $rgname; +$diskEncryptionKeyVaultUrl = $keyVault.VaultUri; +$keyVaultResourceId = $keyVault.ResourceId; + +$kek = Add-AzureKeyVaultKey -VaultName $vaultName -Name $kekName -Destination "Software" +$keyEncryptionKeyUrl = $kek.Key.kid; + +Set-AzureRmVMDiskEncryptionExtension -ResourceGroupName $rgname -VMName $vmName -AadClientID $aadClientID -AadClientSecret $aadClientSecret -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl -DiskEncryptionKeyVaultId $keyVaultResourceId -KeyEncryptionKeyUrl $keyEncryptionKeyUrl -KeyEncryptionKeyVaultId $keyVaultResourceId; + + + + + + + + + + + + + + + + -------------------------- Enable encryption using AAD Client ID , Client cert Thumbprint and wrap diskEncryptionKey with KeyEncryptionKey -------------------------- + + PS C:\> + + $rgName = 'MyResourceGroup'; +$vmName = 'MyWindowsVM'; + +#The KeyVault must have enabledForDiskEncryption property set on it +$vaultName= 'MyKeyVault'; +$keyVault = Get-AzureRmKeyVault -VaultName $vaultName -ResourceGroupName $rgname; +$diskEncryptionKeyVaultUrl = $keyVault.VaultUri; +$keyVaultResourceId = $keyVault.ResourceId; + +$kek = Add-AzureKeyVaultKey -VaultName $vaultName -Name $kekName -Destination "Software" +$keyEncryptionKeyUrl = $kek.Key.kid; + +# create AAD application and associate the certificate +$certPath = 'C:\certificates\examplecert.pfx'; +$certPassword = 'yourPassword'; +$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certPath, $certPassword); +$keyValue = [System.Convert]::ToBase64String($cert.GetRawCertData()); +$azureAdApplication = New-AzureRmADApplication -DisplayName "<Your Application Display Name>" -HomePage "<https://YourApplicationHomePage>" -IdentifierUris "<https://YouApplicationUri>" -KeyValue $keyValue -KeyType AsymmetricX509Cert ; +$servicePrincipal = New-AzureRmADServicePrincipal –ApplicationId $azureAdApplication.ApplicationId; + +$aadClientID = $azureAdApplication.ApplicationId; +$aadClientCertThumbprint= $cert.Thumbprint; + +#Upload pfx to KeyVault +$keyVaultSecretName = 'myaadcert'; +$fileContentBytes = get-content $certPath -Encoding Byte; +$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes); +$jsonObject = @" { "data": "$filecontentencoded", "dataType" :"pfx", "password": "$certPassword" } "@ ; +$jsonObjectBytes = [System.Text.Encoding]::UTF8.GetBytes($jsonObject); +$jsonEncoded = [System.Convert]::ToBase64String($jsonObjectBytes); + +$secret = ConvertTo-SecureString -String $jsonEncoded -AsPlainText -Force; +Set-AzureKeyVaultSecret -VaultName $vaultName-Name $keyVaultSecretName -SecretValue $secret; +Set-AzureRmKeyVaultAccessPolicy -VaultName $vaultName -ResourceGroupName $rgName –EnabledForDeployment; + +#deploy cert to VM +$certUrl = (Get-AzureKeyVaultSecret -VaultName $vaultName -Name $keyVaultSecretName).Id +$sourceVaultId = (Get-AzureRmKeyVault -VaultName $vaultName -ResourceGroupName $rgName).ResourceId +$vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName +$vm = Add-AzureRmVMSecret -VM $vm -SourceVaultId $sourceVaultId -CertificateStore "My" -CertificateUrl $certUrl +Update-AzureRmVM -VM $vm -ResourceGroupName $rgName + +#Enable encryption on the VM using AAD client ID and client cert thumbprint +Set-AzureRmVMDiskEncryptionExtension -ResourceGroupName $rgname -VMName $vmName -AadClientID $aadClientID -AadClientCertThumbprint $aadClientCertThumbprint -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl -DiskEncryptionKeyVaultId $keyVaultResourceId ; + + + + + + + + + + + + + + + + + + + + + + Set-AzureRmVMDscExtension + + Configure the Windows PowerShell Desired State Configuration extension on a VM. + + + + + Set + AzureRmVMDscExtension + + + + Configure the Windows PowerShell Desired State Configuration extension on a VM in a resource group + + + + Set-AzureRmVMDscExtension + + ResourceGroupName + + The name of the resource group that contains the virtual machine + + String + + + VMName + + Name of the virtual machine where dsc extension handler would be installed + + String + + + Name + + Name of the ARM resource that represents the extension. This is defaulted to 'Microsoft.Powershell.DSC' + + String + + + ArchiveBlobName + + The name of the configuration file that was previously uploaded by Publish-AzureRmVMDSCConfiguration + + String + + + ArchiveStorageAccountName + + The Azure Storage Account name used to download the ArchiveBlobName + + String + + + ArchiveResourceGroupName + + The name of the resource group that contains the storage account containing the configuration archive. This param is optional if storage account and virtual machine both exists in the same resource group name,specified by ResourceGroupName param. + + String + + + ArchiveStorageEndpointSuffix + + The Storage Endpoint Suffix + + String + + + ArchiveContainerName + + Name of the Azure Storage Container where the configuration archive is located + + String + + + ConfigurationName + + Name of the configuration that will be invoked by the DSC Extension + + String + + + ConfigurationArgument + + A hashtable specifying the arguments to the ConfigurationFunction + + Hashtable + + + ConfigurationData + + Path to a .psd1 file that specifies the data for the Configuration + + String + + + Version + + The version of the DSC extension that Set-AzureRmVMDSCExtension will apply the settings to. Allowed format N.N + + String + + + Force + + By default Set-AzureRmVMDscExtension will not overwrite any existing blobs. Use -Force to overwrite them + + SwitchParameter + + + Location + + Location of the resource + + String + + + AutoUpdate + + We install the extension handler version specified by the -version param. By default extension handler is not autoupdated. Use -AutoUpdate to enable auto update of extension handler to the latest version as and when it is available. + + SwitchParameter + + + WmfVersion + + + Specifies the version of the Windows Management Framework (WMF) to install on the VM. The DSC Azure Extension depends on DSC features that are only available in the WMF updates. This parameter specifies which version of the update to install on the VM. The possible values are "4.0","latest" and "5.0PP". + A value of "4.0" will install KB3000850 (http://support.microsoft.com/kb/3000850) on Windows 8.1 or Windows Server 2012 R2, or WMF 4.0 (http://www.microsoft.com/en-us/download/details.aspx?id=40855) on other versions of Windows if a newer version isnt already installed. + A value of "5.0PP" will install the latest release of WMF 5.0PP (http://go.microsoft.com/fwlink/?LinkId=398175). A value of "latest" will install the latest WMF, currently WMF 5.0PP. The default value is "latest" + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + WhatIf + + Describes what would happen if you executed the command without actually executing the command. + + SwitchParameter + + + Confirm + + Prompts you for confirmation before executing the command. + + SwitchParameter + + + + + + ResourceGroupName + + The name of the resource group that contains the virtual machine + + String + + String + + + + + + VMName + + Name of the virtual machine where dsc extension handler would be installed + + String + + String + + + + + + Name + + Name of the ARM resource that represents the extension. This is defaulted to 'Microsoft.Powershell.DSC' + + String + + String + + + + + + ArchiveBlobName + + The name of the configuration file that was previously uploaded by Publish-AzureRmVMDSCConfiguration + + String + + String + + + + + + ArchiveStorageAccountName + + The Azure Storage Account name used to download the ArchiveBlobName + + String + + String + + + + + + ArchiveResourceGroupName + + The name of the resource group that contains the storage account containing the configuration archive. This param is optional if storage account and virtual machine both exists in the same resource group name,specified by ResourceGroupName param. + + String + + String + + + + + + ArchiveStorageEndpointSuffix + + The Storage Endpoint Suffix + + String + + String + + + + + + ArchiveContainerName + + Name of the Azure Storage Container where the configuration archive is located + + String + + String + + + + + + ConfigurationName + + Name of the configuration that will be invoked by the DSC Extension + + String + + String + + + + + + ConfigurationArgument + + A hashtable specifying the arguments to the ConfigurationFunction + + Hashtable + + Hashtable + + + + + + ConfigurationData + + Path to a .psd1 file that specifies the data for the Configuration + + String + + String + + + + + + Version + + The version of the DSC extension that Set-AzureRmVMDSCExtension will apply the settings to. Allowed format N.N + + String + + String + + + + + + Force + + By default Set-AzureRmVMDscExtension will not overwrite any existing blobs. Use -Force to overwrite them + + SwitchParameter + + SwitchParameter + + + + + + Location + + Location of the resource + + String + + String + + + + + + AutoUpdate + + We install the extension handler version specified by the -version param. By default extension handler is not autoupdated. Use -AutoUpdate to enable auto update of extension handler to the latest version as and when it is available. + + SwitchParameter + + SwitchParameter + + + + + + WmfVersion + + + Specifies the version of the Windows Management Framework (WMF) to install on the VM. The DSC Azure Extension depends on DSC features that are only available in the WMF updates. This parameter specifies which version of the update to install on the VM. The possible values are "4.0","latest" and "5.0PP". + A value of "4.0" will install KB3000850 (http://support.microsoft.com/kb/3000850) on Windows 8.1 or Windows Server 2012 R2, or WMF 4.0 (http://www.microsoft.com/en-us/download/details.aspx?id=40855) on other versions of Windows if a newer version isnt already installed. + A value of "5.0PP" will install the latest release of WMF 5.0PP (http://go.microsoft.com/fwlink/?LinkId=398175). A value of "latest" will install the latest WMF, currently WMF 5.0PP. The default value is "latest" + + String + + String + + + latest + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + WhatIf + + Describes what would happen if you executed the command without actually executing the command. + + SwitchParameter + + SwitchParameter + + + + + + Confirm + + Prompts you for confirmation before executing the command. + + SwitchParameter + + SwitchParameter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\> + + Set-AzureRmVMDscExtension -ResourceGroupName Name -VMName VM -ArchiveBlobName Sample.ps1.zip -ArchiveStorageAccountName Stg -ConfigurationName ConfigName -Version 1.10 -Location 'West US' + + Description + + + + + + + + + + + + + + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\> + + Set-AzureRmVMDscExtension -ResourceGroupName Name -VMName vm -ArchiveBlobName Sample.ps1.zip -ArchiveStorageAccountName Stg -ConfigurationName ConfigName -ConfigurationArgument @{arg="val"} -ArchiveContainerName WindowsPowerShellDSC -ConfigurationData SampleData.psd1 -Version 1.10 -Location 'West US' + + Description + + + + + + + + + + + + + + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\> + + Set-AzureRmVMDscExtension -ResourceGroupName Name -VMName vm -ArchiveBlobName Sample.ps1.zip -ArchiveStorageAccountName Stg -ConfigurationName ConfigName -ConfigurationArgument @{arg="val"} -ArchiveContainerName WindowsPowerShellDSC -ConfigurationData SampleData.psd1 -Version 1.10 -Location 'West US' -AutoUpdate + + Description + + + + + + + + + + + + + + + + Unknown + + + + + + + + Set-AzureRmVMExtension + + Updates extension properties or adds an extension to a virtual machine. + + + + + Set + AzureRmVMExtension + + + + The Set-AzureRmVMExtension cmdlet updates properties for existing Virtual Machine Extensions or adds an extension to a virtual machine. + + + + Set-AzureRmVMExtension + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + VMName + + Specifies the name of a virtual machine. This cmdlet modifies extensions for the virtual machine that this parameter specifies. + + String + + + Name + + Specifies the name of an extension. + + String + + + Publisher + + Specifies the name of the extension publisher. The publisher provides a name when the publisher registers an extension. + + String + + + ExtensionType + + Specifies the extension type. + + String + + + TypeHandlerVersion + + Specifies the version of the extension to use for this virtual machine. + + String + + + Settings + + Specifies public configuration for the extension, as a hash table. This cmdlet does not encrypt public configuration. + + Hashtable + + + ProtectedSettings + + Specifies private configuration for the extension, as a hash table. This cmdlet encrypts the private configuration. + + Hashtable + + + Location + + Specifies the location of the virtual machine. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Set-AzureRmVMExtension + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + VMName + + Specifies the name of a virtual machine. This cmdlet modifies extensions for the virtual machine that this parameter specifies. + + String + + + Name + + Specifies the name of an extension. + + String + + + Publisher + + Specifies the name of the extension publisher. The publisher provides a name when the publisher registers an extension. + + String + + + ExtensionType + + Specifies the extension type. + + String + + + TypeHandlerVersion + + Specifies the version of the extension to use for this virtual machine. + + String + + + SettingString + + Specifies public configuration for the extension, as a string. This cmdlet does not encrypt public configuration. + + String + + + ProtectedSettingString + + Specifies private configuration for the extension, as a string. This cmdlet encrypts the private configuration. + + String + + + Location + + Specifies the location of the virtual machine. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + VMName + + Specifies the name of a virtual machine. This cmdlet modifies extensions for the virtual machine that this parameter specifies. + + String + + String + + + none + + + Name + + Specifies the name of an extension. + + String + + String + + + none + + + Publisher + + Specifies the name of the extension publisher. The publisher provides a name when the publisher registers an extension. + + String + + String + + + none + + + ExtensionType + + Specifies the extension type. + + String + + String + + + none + + + TypeHandlerVersion + + Specifies the version of the extension to use for this virtual machine. + + String + + String + + + none + + + Settings + + Specifies public configuration for the extension, as a hash table. This cmdlet does not encrypt public configuration. + + Hashtable + + Hashtable + + + none + + + ProtectedSettings + + Specifies private configuration for the extension, as a hash table. This cmdlet encrypts the private configuration. + + Hashtable + + Hashtable + + + none + + + Location + + Specifies the location of the virtual machine. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + SettingString + + Specifies public configuration for the extension, as a string. This cmdlet does not encrypt public configuration. + + String + + String + + + none + + + ProtectedSettingString + + Specifies private configuration for the extension, as a string. This cmdlet encrypts the private configuration. + + String + + String + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Modify settings by using hash tables -------------------------- + + PS C:\> + + PS C:\>$Settings = @{"fileUris" = "[]"; "commandToExecute" = ""}; +PS C:\> $ProtectedSettings = @{"storageAccountName" = $stoname; "storageAccountKey" = $stokey}; +PS C:\> Set-AzureRmVMExtension -ResourceGroupName "ResourceGroup11" -Location "West US" -VMName "VirtualMachine22" -Name "ContosoTest" -Publisher "Contoso.Compute" -Type "CustomScriptExtension" -TypeHandlerVersion "1.1" -Settings $Settings -ProtectedSettings $ProtectedSettings; + + The first two commands use standard Windows PowerShell® syntax to create hash tables, and then stores those hash tables in the $Settings and $ProtectedSettings variables. For more information, type Get-Help about_Hash_Tables. The second command includes two values previously created and stored in variables. + + + + + + + + + + + + + + -------------------------- Example 2: Modify settings by using strings -------------------------- + + PS C:\> + + PS C:\>$SettingsString = '{"fileUris":[],"commandToExecute":""}'; +PS C:\> $ProtectedSettingsString = '{"storageAccountName":"' + $stoname + '","storageAccountKey":"' + $stokey + '"}'; +PS C:\> Set-AzureRmVMExtension -ResourceGroupName "ResourceGroup11" -Location "West US" -VMName "VirtualMachine22" -Name "CustomScriptExtension" -Publisher "Contoso.Compute" -Type "CustomScriptExtension" -TypeHandlerVersion "1.1" -SettingString $SettingsString -ProtectedSettingString $ProtectedSettingsString ; + + The first two commands create strings that contain settings, and then stores them in the $SettingsString and $ProtectedSettingsString variables. + + + + + + + + + + + + + + + + Get-AzureRmVMExtension + + + + Remove-AzureRmVMExtension + + + + + + + + Set-AzureRmVMOperatingSystem + + Sets operating system properties for a virtual machine. + + + + + Set + AzureRmVMOperatingSystem + + + + The Set-AzureRmVMOperatingSystem cmdlet sets operating system properties for a virtual machine. You can specify logon credentials computer name, and operating system type. + + + + Set-AzureRmVMOperatingSystem + + VM + + Specifies the local virtual machine object on which to set operating system properties. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. Create a virtual machine object by using the New-AzureRmVMConfig cmdlet. + + PSVirtualMachine + + + Windows + + Indicates that the type of operating system is Windows. + + SwitchParameter + + + ComputerName + + Specifies the name of the computer. + + String + + + Credential + + Specifies the user name and password for the virtual machine as a PSCredential object. To obtain a credential, use the Get-Credential cmdlet. For more information, type Get-Help Get-Credential. + + PSCredential + + + CustomData + + Specifies a base-64 encoded string of custom data. This is decoded to a binary array that is saved as a file on the virtual machine. The maximum length of the binary array is 65535 bytes. + + String + + + ProvisionVMAgent + + Indicates that the settings require that the virtual machine agent be installed on the virtual machine. + + SwitchParameter + + + EnableAutoUpdate + + Indicates that this cmdlet enables auto update. + + SwitchParameter + + + TimeZone + + Specifies the time zone for the virtual machine. + + String + + + WinRMHttp + + Indicates that this operating system uses HTTP WinRM. + + SwitchParameter + + + WinRMHttps + + Indicates that this operating system uses HTTPS WinRM. + + SwitchParameter + + + WinRMCertificateUrl + + Specifies the URI of a WinRM certificate. This needs to be stored in a Key Vault. + + Uri + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Set-AzureRmVMOperatingSystem + + VM + + Specifies the local virtual machine object on which to set operating system properties. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. Create a virtual machine object by using the New-AzureRmVMConfig cmdlet. + + PSVirtualMachine + + + Linux + + Indicates that the type of operating system is Linux. + + SwitchParameter + + + ComputerName + + Specifies the name of the computer. + + String + + + Credential + + Specifies the user name and password for the virtual machine as a PSCredential object. To obtain a credential, use the Get-Credential cmdlet. For more information, type Get-Help Get-Credential. + + PSCredential + + + CustomData + + Specifies a base-64 encoded string of custom data. This is decoded to a binary array that is saved as a file on the virtual machine. The maximum length of the binary array is 65535 bytes. + + String + + + DisablePasswordAuthentication + + Indicates that this cmdlet disables password authentication. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + Specifies the local virtual machine object on which to set operating system properties. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. Create a virtual machine object by using the New-AzureRmVMConfig cmdlet. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + Windows + + Indicates that the type of operating system is Windows. + + SwitchParameter + + SwitchParameter + + + none + + + ComputerName + + Specifies the name of the computer. + + String + + String + + + none + + + Credential + + Specifies the user name and password for the virtual machine as a PSCredential object. To obtain a credential, use the Get-Credential cmdlet. For more information, type Get-Help Get-Credential. + + PSCredential + + PSCredential + + + none + + + CustomData + + Specifies a base-64 encoded string of custom data. This is decoded to a binary array that is saved as a file on the virtual machine. The maximum length of the binary array is 65535 bytes. + + String + + String + + + none + + + ProvisionVMAgent + + Indicates that the settings require that the virtual machine agent be installed on the virtual machine. + + SwitchParameter + + SwitchParameter + + + none + + + EnableAutoUpdate + + Indicates that this cmdlet enables auto update. + + SwitchParameter + + SwitchParameter + + + none + + + TimeZone + + Specifies the time zone for the virtual machine. + + String + + String + + + none + + + WinRMHttp + + Indicates that this operating system uses HTTP WinRM. + + SwitchParameter + + SwitchParameter + + + none + + + WinRMHttps + + Indicates that this operating system uses HTTPS WinRM. + + SwitchParameter + + SwitchParameter + + + none + + + WinRMCertificateUrl + + Specifies the URI of a WinRM certificate. This needs to be stored in a Key Vault. + + Uri + + Uri + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Linux + + Indicates that the type of operating system is Linux. + + SwitchParameter + + SwitchParameter + + + none + + + DisablePasswordAuthentication + + Indicates that this cmdlet disables password authentication. + + SwitchParameter + + SwitchParameter + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Set operating system properties for a new virtual machines -------------------------- + + PS C:\> + + PS C:\>$SecurePassword = ConvertTo-SecureString "password" -AsPlainText -Force +PS C:\> $Credential = New-Object System.Management.Automation.PSCredential ("FullerP", $SecurePassword); +PS C:\> $AvailabilitySet = Get-AzureRmAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet03" +PS C:\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" -AvailabilitySetID $AvailabilitySet.Id +PS C:\> $ComputerName = "ContosoVM122" +PS C:\> $WinRMCertUrl = "http://keyVaultName.vault.azure.net/secrets/secretName/secretVersion" +PS C:\> $TimeZone = "Pacific Standard Time" +PS C:\> $CustomData = "echo 'Hello World'" +PS C:\> $VirtualMachine = Set-AzureRmVMOperatingSystem -VM $$VirtualMachine -Windows -ComputerName $ComputerName -Credential $Credential -CustomData $CustomData -WinRMHttp -WinRMHttps -WinRMCertificateUrl $WinRMCertUrl -ProvisionVMAgent -EnableAutoUpdate -TimeZone $TimeZone + + The first command converts a password to a secure string, and then stores it in the $SecurePassword variable. For more information, type Get-Help ConvertTo-SecureString. + + + The fourth command creates a virtual machine object, and then stores it in the $VirtualMachine variable. The command assigns a name and size to the virtual machine. The virtual machine belongs to the availability set stored in $AvailabilitySet. + + + + + + + + + + + + + Get-AzureRmVM + + + + New-AzureRmVMConfig + + + + + + + + Set-AzureRmVMOSDisk + + Sets the operating system disk properties on a virtual machine. + + + + + Set + AzureRmVMOSDisk + + + + The Set-AzureRmVMOSDisk cmdlet set the operating system disk properties on a virtual machine. + + + + Set-AzureRmVMOSDisk + + VM + + Specifies the local virtual machine object on which to set operating system disk properties. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + + Name + + Specifies the name of the operating system disk. + + String + + + VhdUri + + Specifies the Uniform Resource Identifier (URI) of a virtual hard disk (VHD). + For an image based virtual machine, this parameter specifies the VHD file to create when a platform image or user image is specified. This is the location from which the image binary large object (BLOB) is copied to start the virtual machine. + For a disk based virtual machine boot scenario, this parameter specifies the VHD file that the virtual machine uses directly for starting up. + + String + + + Caching + + Specifies the caching mode of the operating system disk. Valid values are: + -- ReadOnly +-- ReadWrite + The default value is ReadWrite. Changing the caching value causes the virtual machine to restart. + This setting affects the consistency and performance of the disk. + + String + + + SourceImageUri + + This setting affects the consistency and performance of the disk. + + String + + + CreateOption + + Specifies whether this cmldet creates a disk in the virtual machine from a platform or user image, creates an empty disk, or attaches an existing disk. Valid values are: + -- Attach +-- Empty +-- FromImage + This setting affects the consistency and performance of the disk. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Set-AzureRmVMOSDisk + + VM + + Specifies the local virtual machine object on which to set operating system disk properties. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + + Name + + Specifies the name of the operating system disk. + + String + + + VhdUri + + Specifies the Uniform Resource Identifier (URI) of a virtual hard disk (VHD). + For an image based virtual machine, this parameter specifies the VHD file to create when a platform image or user image is specified. This is the location from which the image binary large object (BLOB) is copied to start the virtual machine. + For a disk based virtual machine boot scenario, this parameter specifies the VHD file that the virtual machine uses directly for starting up. + + String + + + Caching + + Specifies the caching mode of the operating system disk. Valid values are: + -- ReadOnly +-- ReadWrite + The default value is ReadWrite. Changing the caching value causes the virtual machine to restart. + This setting affects the consistency and performance of the disk. + + String + + + SourceImageUri + + This setting affects the consistency and performance of the disk. + + String + + + CreateOption + + Specifies whether this cmldet creates a disk in the virtual machine from a platform or user image, creates an empty disk, or attaches an existing disk. Valid values are: + -- Attach +-- Empty +-- FromImage + This setting affects the consistency and performance of the disk. + + String + + + Windows + + Indicates that the operating system on the user image is Windows. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Set-AzureRmVMOSDisk + + VM + + Specifies the local virtual machine object on which to set operating system disk properties. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + + Name + + Specifies the name of the operating system disk. + + String + + + VhdUri + + Specifies the Uniform Resource Identifier (URI) of a virtual hard disk (VHD). + For an image based virtual machine, this parameter specifies the VHD file to create when a platform image or user image is specified. This is the location from which the image binary large object (BLOB) is copied to start the virtual machine. + For a disk based virtual machine boot scenario, this parameter specifies the VHD file that the virtual machine uses directly for starting up. + + String + + + Caching + + Specifies the caching mode of the operating system disk. Valid values are: + -- ReadOnly +-- ReadWrite + The default value is ReadWrite. Changing the caching value causes the virtual machine to restart. + This setting affects the consistency and performance of the disk. + + String + + + SourceImageUri + + This setting affects the consistency and performance of the disk. + + String + + + CreateOption + + Specifies whether this cmldet creates a disk in the virtual machine from a platform or user image, creates an empty disk, or attaches an existing disk. Valid values are: + -- Attach +-- Empty +-- FromImage + This setting affects the consistency and performance of the disk. + + String + + + Windows + + Indicates that the operating system on the user image is Windows. + + SwitchParameter + + + DiskEncryptionKeyUrl + + + + String + + + DiskEncryptionKeyVaultId + + + + String + + + KeyEncryptionKeyUrl + + + + String + + + KeyEncryptionKeyVaultId + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Set-AzureRmVMOSDisk + + VM + + Specifies the local virtual machine object on which to set operating system disk properties. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + + Name + + Specifies the name of the operating system disk. + + String + + + VhdUri + + Specifies the Uniform Resource Identifier (URI) of a virtual hard disk (VHD). + For an image based virtual machine, this parameter specifies the VHD file to create when a platform image or user image is specified. This is the location from which the image binary large object (BLOB) is copied to start the virtual machine. + For a disk based virtual machine boot scenario, this parameter specifies the VHD file that the virtual machine uses directly for starting up. + + String + + + Caching + + Specifies the caching mode of the operating system disk. Valid values are: + -- ReadOnly +-- ReadWrite + The default value is ReadWrite. Changing the caching value causes the virtual machine to restart. + This setting affects the consistency and performance of the disk. + + String + + + SourceImageUri + + This setting affects the consistency and performance of the disk. + + String + + + CreateOption + + Specifies whether this cmldet creates a disk in the virtual machine from a platform or user image, creates an empty disk, or attaches an existing disk. Valid values are: + -- Attach +-- Empty +-- FromImage + This setting affects the consistency and performance of the disk. + + String + + + Linux + + Indicates that the operating system on the user image is Linux. Specify this parameter for user image based virtual machine deployment. + + SwitchParameter + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Set-AzureRmVMOSDisk + + VM + + Specifies the local virtual machine object on which to set operating system disk properties. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + + Name + + Specifies the name of the operating system disk. + + String + + + VhdUri + + Specifies the Uniform Resource Identifier (URI) of a virtual hard disk (VHD). + For an image based virtual machine, this parameter specifies the VHD file to create when a platform image or user image is specified. This is the location from which the image binary large object (BLOB) is copied to start the virtual machine. + For a disk based virtual machine boot scenario, this parameter specifies the VHD file that the virtual machine uses directly for starting up. + + String + + + Caching + + Specifies the caching mode of the operating system disk. Valid values are: + -- ReadOnly +-- ReadWrite + The default value is ReadWrite. Changing the caching value causes the virtual machine to restart. + This setting affects the consistency and performance of the disk. + + String + + + SourceImageUri + + This setting affects the consistency and performance of the disk. + + String + + + CreateOption + + Specifies whether this cmldet creates a disk in the virtual machine from a platform or user image, creates an empty disk, or attaches an existing disk. Valid values are: + -- Attach +-- Empty +-- FromImage + This setting affects the consistency and performance of the disk. + + String + + + Linux + + Indicates that the operating system on the user image is Linux. Specify this parameter for user image based virtual machine deployment. + + SwitchParameter + + + DiskEncryptionKeyUrl + + + + String + + + DiskEncryptionKeyVaultId + + + + String + + + KeyEncryptionKeyUrl + + + + String + + + KeyEncryptionKeyVaultId + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + Specifies the local virtual machine object on which to set operating system disk properties. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + Name + + Specifies the name of the operating system disk. + + String + + String + + + none + + + VhdUri + + Specifies the Uniform Resource Identifier (URI) of a virtual hard disk (VHD). + For an image based virtual machine, this parameter specifies the VHD file to create when a platform image or user image is specified. This is the location from which the image binary large object (BLOB) is copied to start the virtual machine. + For a disk based virtual machine boot scenario, this parameter specifies the VHD file that the virtual machine uses directly for starting up. + + String + + String + + + none + + + Caching + + Specifies the caching mode of the operating system disk. Valid values are: + -- ReadOnly +-- ReadWrite + The default value is ReadWrite. Changing the caching value causes the virtual machine to restart. + This setting affects the consistency and performance of the disk. + + String + + String + + + none + + + SourceImageUri + + This setting affects the consistency and performance of the disk. + + String + + String + + + none + + + CreateOption + + Specifies whether this cmldet creates a disk in the virtual machine from a platform or user image, creates an empty disk, or attaches an existing disk. Valid values are: + -- Attach +-- Empty +-- FromImage + This setting affects the consistency and performance of the disk. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Windows + + Indicates that the operating system on the user image is Windows. + + SwitchParameter + + SwitchParameter + + + none + + + DiskEncryptionKeyUrl + + + + String + + String + + + + + + DiskEncryptionKeyVaultId + + + + String + + String + + + + + + KeyEncryptionKeyUrl + + + + String + + String + + + + + + KeyEncryptionKeyVaultId + + + + String + + String + + + + + + Linux + + Indicates that the operating system on the user image is Linux. Specify this parameter for user image based virtual machine deployment. + + SwitchParameter + + SwitchParameter + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Sets properties on a virtual machine -------------------------- + + PS C:\> + + PS C:\>$AvailabilitySet = Get-AzureRmAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet03" +PS C:\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" -AvailabilitySetID $AvailabilitySet.Id +PS C:\> Set-AzureRmVMOSDisk -VM $VirtualMachine -Name "OsDisk02" -VhdUri "os.vhd" -Caching ReadWrite + + The first command gets the availability set named AvailablitySet03 in the resource group named ResourceGroup11, and then stores that object in the $AvailabilitySet variable. + + + + + + + + + + + + + + + + Get-AzureRmVM + + + + Get-AzureRmAvailabilitySet + + + + New-AzureRmVMConfig + + + + + + + + Set-AzureRmVMSourceImage + + Specifies the platform image for a virtual machine. + + + + + Set + AzureRmVMSourceImage + + + + The Set-AzureRmVMSourceImage cmdlet specifies the platform image to use for a virtual machine. + + + + Set-AzureRmVMSourceImage + + VM + + Specifies the local virtual machine object to configure. + + PSVirtualMachine + + + PublisherName + + Specifies the name of a publisher of a VMImage. To obtain a publisher, use the Get-AzureRmVMImagePublisher cmdlet. + + String + + + Offer + + Specifies the type of VMImage offer. To obtain an image offer, use the Get-AzureRmVMImageOffer cmdlet. + + String + + + Skus + + Specfies a VMImage SKU. To obtain SKUs, use the Get-AzureRmVMImageSku cmdlet. + + String + + + Version + + Specifies a version of a VMImage. To use the latest version, specify a value of latest instead of a particular version. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + Specifies the local virtual machine object to configure. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + PublisherName + + Specifies the name of a publisher of a VMImage. To obtain a publisher, use the Get-AzureRmVMImagePublisher cmdlet. + + String + + String + + + none + + + Offer + + Specifies the type of VMImage offer. To obtain an image offer, use the Get-AzureRmVMImageOffer cmdlet. + + String + + String + + + none + + + Skus + + Specfies a VMImage SKU. To obtain SKUs, use the Get-AzureRmVMImageSku cmdlet. + + String + + String + + + none + + + Version + + Specifies a version of a VMImage. To use the latest version, specify a value of latest instead of a particular version. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Name + + Specifies the name of a source image. + + system.string + + system.string + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + microsoft.azure.common.authentication.models.azureprofile + + microsoft.azure.common.authentication.models.azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Set values for an image -------------------------- + + PS C:\> + + PS C:\>AvailabilitySet = Get-AzureRmAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet03" +PS C:\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" -AvailabilitySetID $AvailabilitySet.Id +PS C:\> Set-AzureRmVMSourceImage -VM $VirtualMachine -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus "2012-R2-Datacenter" -Version "latest" + + The first command gets the availability set named AvailablitySet03 in the resource group named ResourceGroup11, and then stores that object in the $AvailabilitySet variable. + + + + + + + + + + + + + + -------------------------- Example 2: Use the image reference method to set values -------------------------- + + PS C:\> + + PS C:\>$Publisher = (Get-AzureRmVMImagePublisher -Location "Central US") | select -ExpandProperty PublisherName | where { $_ -like '*Microsoft*Windows*Server' } +PS C:\> $Offer = (Get-AzureRmVMImageOffer -Location "Central US" -PublisherName $Publisher[0]) | select -ExpandProperty Offer | where { $_ -like '*Windows*' } +PS C:\> $Sku = (Get-AzureRmVMImageSku -Location "Central US" -PublisherName $Publisher[0] -Offer $Offer[0]) | select -ExpandProperty Skus +PS C:\> $Versions = (Get-AzureRmVMImage -Location "Central US" -Offer -Offer $Offer[0] -PublisherName $Publisher[0] -Skus $Sku[0]) | select -ExpandProperty Version +PS C:\> $VMImage = Get-AzureRmVMImage -Location "Central US" -Offer -Offer $Offer[0] -PublisherName $Publisher[0] -Skus $Sku[0] -Version $Versions[0] +PS C:\> $VirtualMachine07 = Set-AzureRmVMSourceImage -VM $VirtualMachine07 -ImageReference $VMImage + + This example sets source image settings by using the image reference method. + + + + + + + + + + + + + + + + Get-AzureRmAvailabilitySet + + + + New-AzureRmVMConfig + + + + Get-AzureRmVMImagePublisher + + + + Get-AzureRmVMImageOffer + + + + Get-AzureRmVMImageSku + + + + Get-AzureRmVMImage + + + + + + + + Set-AzureRmVMSqlServerExtension + + + + + + + Set + AzureRmVMSqlServerExtension + + + + + + + + Set-AzureRmVMSqlServerExtension + + Version + + + + String + + + ResourceGroupName + + + + String + + + VMName + + + + String + + + Name + + + + String + + + AutoPatchingSettings + + + + AutoPatchingSettings + + + AutoBackupSettings + + + + AutoBackupSettings + + + Location + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Version + + + + String + + String + + + + + + ResourceGroupName + + + + String + + String + + + + + + VMName + + + + String + + String + + + + + + Name + + + + String + + String + + + + + + AutoPatchingSettings + + + + AutoPatchingSettings + + AutoPatchingSettings + + + + + + AutoBackupSettings + + + + AutoBackupSettings + + AutoBackupSettings + + + + + + Location + + + + String + + String + + + + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Start-AzureRmVM + + Starts an Azure virtual machine. + + + + + Start + AzureRmVM + + + + The Start-AzureRmVM cmdlet starts an Azure virtual machine. + + + + Start-AzureRmVM + + Name + + Specifies the name of the virtual machine to start. + + String + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Start-AzureRmVM + + Name + + Specifies the name of the virtual machine to start. + + String + + + Id + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Name + + Specifies the name of the virtual machine to start. + + String + + String + + + none + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Id + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Start a virtual machine -------------------------- + + PS C:\> + + PS C:\>Start-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" + + This command starts the virtual machine named VirtualMachine07 in ResourceGroup11. + + + + + + + + + + + + + + + + Get-AzureRmVM + + + + New-AzureRmVM + + + + Remove-AzureRmVM + + + + Restart-AzureRmVM + + + + Stop-AzureRmVM + + + + Update-AzureRmVM + + + + + + + + Stop-AzureRmVM + + Stops an Azure virtual machine. + + + + + Stop + AzureRmVM + + + + The Stop-AzureRmVM cmdlet stops an Azure virtual machine. + + + + Stop-AzureRmVM + + Name + + Specifies the name of the virtual machine to stop. + + String + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + + StayProvisioned + + Indicates that this cmdlet uses the stay provisioned setting. + + SwitchParameter + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Stop-AzureRmVM + + Name + + Specifies the name of the virtual machine to stop. + + String + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + + StayProvisioned + + Indicates that this cmdlet uses the stay provisioned setting. + + SwitchParameter + + + Id + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + Name + + Specifies the name of the virtual machine to stop. + + String + + String + + + none + + + Force + + Forces the command to run without asking for user confirmation. + + SwitchParameter + + SwitchParameter + + + none + + + StayProvisioned + + Indicates that this cmdlet uses the stay provisioned setting. + + SwitchParameter + + SwitchParameter + + + none + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Id + + + + String + + String + + + + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Stop a virtual machine -------------------------- + + PS C:\> + + PS C:\>Stop-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" + + This command stops the virtual machine named VirtualMachine07 in ResourceGroup11. + + + + + + + + + + + + + + + + Get-AzureRmVM + + + + New-AzureRmVM + + + + Remove-AzureRmVM + + + + Restart-AzureRmVM + + + + Start-AzureRmVM + + + + Update-AzureRmVM + + + + + + + + Update-AzureRmVM + + Updates the state of an Azure virtual machine. + + + + + Update + AzureRmVM + + + + The Update-AzureRmVM cmdlet updates the state of an Azure virtual machine to the state of a virtual machine object. + + + + Update-AzureRmVM + + VM + + Specifies a local virtual machine object. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. This virtual machine object contains the updated state for the virtual machine. + + PSVirtualMachine + + + Tags + + + + Hashtable[] + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + Update-AzureRmVM + + VM + + Specifies a local virtual machine object. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. This virtual machine object contains the updated state for the virtual machine. + + PSVirtualMachine + + + Tags + + + + Hashtable[] + + + Id + + + + String + + + InformationAction + + + + ActionPreference + + + InformationVariable + + + + String + + + + + + VM + + Specifies a local virtual machine object. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. This virtual machine object contains the updated state for the virtual machine. + + PSVirtualMachine + + PSVirtualMachine + + + none + + + Tags + + + + Hashtable[] + + Hashtable[] + + + none + + + ResourceGroupName + + Specifies the name of a resource group. + + String + + String + + + none + + + InformationAction + + + + ActionPreference + + ActionPreference + + + + + + InformationVariable + + + + String + + String + + + + + + Id + + + + String + + String + + + + + + Name + + Specifies the name of the virtual machine to update. + + string + + string + + + none + + + Profile + + Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile. + + azureprofile + + azureprofile + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- Example 1: Update a virtual machine -------------------------- + + PS C:\> + + PS C:\>Update-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" -VM $VirtualMachine + + This command updates the virtual machine named VirtualMachine07 in ResourceGroup11. The command updates it by using another virtual machine object, stored in the $VirtualMachine variable. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet. + + + + + + + + + + + + + + + + Get-AzureRmVM + + + + New-AzureRmVM + + + + Remove-AzureRmVM + + + + Restart-AzureRmVM + + + + Start-AzureRmVM + + + + Stop-AzureRmVM + + + + New-AzureRmVMConfig + + + + + + + + Get-AzureRmVMExtensionImageDetail + + This cmdlet has been deprecated. + + + + + + + + + + This Get-AzureRmVMExtensionImageDetail cmdlet has been deprecated. + + + + + + FilterExpression + + + + string + + string + + + none + + + Location + + + + string + + string + + + none + + + Profile + + + + azureprofile + + azureprofile + + + none + + + PublisherName + + + + string + + string + + + none + + + Type + + + + string + + string + + + none + + + Version + + + + string + + string + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- 1: -------------------------- + + PS C:\> + + PS C:\> + + + + + + + + + + + + + + + + + + + + + + Get-AzureRmVMImageDetail + + This cmdlet has been deprecated. + + + + + + + + + + The Get-AzureRmVMImageDetail cmdlet has been deprecated. + + + + + + Location + + + + string + + string + + + none + + + Offer + + + + string + + string + + + none + + + Profile + + + + azureprofile + + azureprofile + + + none + + + PublisherName + + + + string + + string + + + none + + + Skus + + + + string + + string + + + none + + + Version + + + + string + + string + + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Keywords: azure, azurerm, arm, resource, management, manager, compute, vm, iaas + + + + + -------------------------- 1: -------------------------- + + PS C:\> + + PS C:\> + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.format.generated.ps1xml b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.format.generated.ps1xml new file mode 100644 index 000000000000..684c288ceab3 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.format.generated.ps1xml @@ -0,0 +1,235 @@ + + + + + + Microsoft.Azure.Commands.Compute.Models.PSAvailabilitySet + + Microsoft.Azure.Commands.Compute.Models.PSAvailabilitySet + + + + + + + + ResourceGroupName + + + + Id + + + + Name + + + + Type + + + + Location + + + + TagsText + + + + PlatformFaultDomainCount + + + + PlatformUpdateDomainCount + + + + StatusesText + + + + VirtualMachinesReferencesText + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineSize + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineSize + + + + + + + + MaxDataDiskCount + + + + MemoryInMB + + + + Name + + + + NumberOfCores + + + + OSDiskSizeInMB + + + + ResourceDiskSizeInMB + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSUsage + + Microsoft.Azure.Commands.Compute.Models.PSUsage + + + + + + + + CurrentValue + + + + Limit + + + + NameText + + + + UnitText + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine + + + + + + + + ResourceGroupName + + + + Id + + + + Name + + + + Type + + + + Location + + + + TagsText + + + + AvailabilitySetReferenceText + + + + DiagnosticsProfileText + + + + ExtensionsText + + + + HardwareProfileText + + + + InstanceViewText + + + + NetworkProfileText + + + + OSProfileText + + + + PlanText + + + + ProvisioningState + + + + StorageProfileText + + + + DataDiskNames + + + + NetworkInterfaceIDs + + + + + + + + diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.format.ps1xml b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.format.ps1xml new file mode 100644 index 000000000000..9f505cf386f0 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.format.ps1xml @@ -0,0 +1,641 @@ + + + + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineInstanceView + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineInstanceView + + + + + + + + ResourceGroupName + + + + Name + + + + BootDiagnosticsText + + + + DisksText + + + + ExtensionsText + + + + PlatformFaultDomain + + + + PlatformUpdateDomain + + + + RemoteDesktopThumbprint + + + + VMAgentText + + + + StatusesText + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSComputeLongRunningOperation + + Microsoft.Azure.Commands.Compute.Models.PSComputeLongRunningOperation + + + + + + + + Status + + + + StatusCode + + + + RequestId + + + + Output + + + + ErrorText + + + + StartTime + + + + EndTime + + + + TrackingOperationId + + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageBase + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageBase + + + + + + + + Id + + + + Location + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImagePublisher + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImagePublisher + + + + + + + + + + + + PublisherName + + + Location + + + Id + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageOffer + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageOffer + + + + + + + + + + + + + Offer + + + PublisherName + + + Location + + + Id + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageSku + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageSku + + + + + + + + + + + + + + Skus + + + Offer + + + PublisherName + + + Location + + + Id + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImage + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImage + + + + + + + + + + + + + + + + Version + + + FilterExpression + + + Skus + + + Offer + + + PublisherName + + + Location + + + Id + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageDetail + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageDetail + + + + + + + + Id + + + + Location + + + + PublisherName + + + + Offer + + + + Skus + + + + Version + + + + FilterExpression + + + + Name + + + + OSDiskImageText + + + + PurchasePlanText + + + + DataDiskImagesText + + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineExtensionImage + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineExtensionImage + + + + + + + + Id + + + + Location + + + + PublisherName + + + + Type + + + + Version + + + + FilterExpression + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineExtensionImageDetails + + Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineExtensionImageDetails + + + + + + + + Id + + + + Location + + + + PublisherName + + + + Type + + + + Version + + + + FilterExpression + + + + Name + + + + HandlerSchema + + + + OperatingSystem + + + + ComputeRole + + + + SupportsMultipleExtensions + + + + VMScaleSetEnabled + + + + + + + + Microsoft.Azure.Management.Compute.Models.DataDisk + + Microsoft.Azure.Management.Compute.Models.DataDisk + + + + + + + + Name + + + + DiskSizeGB + + + + Lun + + + + Caching + + + + CreateOption + + + + SourceImage + + + + + if ($_.VirtualHardDisk -ne $null) + { + $_.VirtualHardDisk.Uri; + } + else + { + $_.VirtualHardDisk; + } + + + + + + + + + + Microsoft.Azure.Commands.Compute.Extension.DSC.VirtualMachineDscExtensionContext + + Microsoft.Azure.Commands.Compute.Extension.DSC.VirtualMachineDscExtensionContext + + + + + + + + ResourceGroupName + + + + Name + + + + Publisher + + + + ExtensionType + + + + TypeHandlerVersion + + + + ProvisioningState + + + + Location + + + + Id + + + + ModulesUrl + + + + ConfigurationFunction + + + + Properties + + + + StatusesText + + + + + + + + + Microsoft.Azure.Commands.Compute.Extension.DSC.VirtualMachineDscExtensionStatusContext + + + Microsoft.Azure.Commands.Compute.Extension.DSC.VirtualMachineDscExtensionStatusContext + + + + + + + + ResourceGroupName + + + + VmName + + + + Version + + + + Status + + + + StatusCode + + + + + $_.Timestamp.ToString("G") + + + + + StatusMessage + + + + DscConfigurationLog + + + + + + + + + Microsoft.Azure.Commands.Compute.Models.AzureDiskEncryptionStatusContext + + + Microsoft.Azure.Commands.Compute.Models.AzureDiskEncryptionStatusContext + + + + + + + + OsVolumeEncrypted + + + + OsVolumeEncryptionSettingsText + + + + DataVolumesEncrypted + + + + + + + + + \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.nuspec.template b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.nuspec.template new file mode 100644 index 000000000000..9205d9704940 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.nuspec.template @@ -0,0 +1,30 @@ + + + + Microsoft.Azure.Commands.Compute + Microsoft Azure Compute Cmdlets + %PackageVersion% + Microsoft + azure-sdk, PowerShell, Microsoft + http://aka.ms/windowsazureapache2 + https://github.com/Azure/azure-powershell + http://go.microsoft.com/fwlink/?LinkID=288890 + true + Cross-Platform cmdlets for Microsoft Azure Compute Management. + + Cross-Platform cmdlets for Microsoft Azure Compute Management. + + Supported Library Platforms: + - .NET Framework 5.0 + + Copyright © Microsoft Corporation + Microsoft "Microsoft Azure" Azure cloud PowerShell WMF Windows Management Framework azureofficial windowsazureofficial + + +%ReferenceFiles% + + + + +%SourceFiles%%ContentFiles% + diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.xproj b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.xproj new file mode 100644 index 000000000000..55ef1c9cbefa --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Microsoft.Azure.Commands.Compute.xproj @@ -0,0 +1,18 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 04f9968a-5662-4508-bee2-31f56848fcba + Microsoft.Azure.Commands.Compute + ..\artifacts\obj\$(MSBuildProjectName) + ..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/AzureDiskEncryptionStatusContext.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/AzureDiskEncryptionStatusContext.cs new file mode 100644 index 000000000000..5870bbb68744 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/AzureDiskEncryptionStatusContext.cs @@ -0,0 +1,18 @@ +using Microsoft.Azure.Management.Compute.Models; +using Newtonsoft.Json; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + class AzureDiskEncryptionStatusContext + { + public bool OsVolumeEncrypted { get; set; } + public DiskEncryptionSettings OsVolumeEncryptionSettings { get; set; } + + [JsonIgnore] + public string OsVolumeEncryptionSettingsText + { + get { return JsonConvert.SerializeObject(OsVolumeEncryptionSettings, Formatting.Indented); } + } + public bool DataVolumesEncrypted { get; set;} + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSAvailabilitySet.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSAvailabilitySet.cs new file mode 100644 index 000000000000..d2a5b5ad84ed --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSAvailabilitySet.cs @@ -0,0 +1,87 @@ +// +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// Warning: This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the +// code is regenerated. + +using Microsoft.Azure.Management.Compute.Models; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSAvailabilitySet : PSOperation + { + // Gets or sets the property of 'ResourceGroupName' + public string ResourceGroupName + { + get + { + Regex r = new Regex(@"(.*?)/resourcegroups/(?\S+)/providers/(.*?)", RegexOptions.IgnoreCase); + Match m = r.Match(Id); + return m.Success ? m.Groups["rgname"].Value : null; + } + } + + // Gets or sets the property of 'Id' + public string Id { get; set; } + + // Gets or sets the property of 'Name' + public string Name { get; set; } + + // Gets or sets the property of 'Type' + public string Type { get; set; } + + // Gets or sets the property of 'Location' + public string Location { get; set; } + + // Gets or sets the property of 'Tags' + public IDictionary Tags { get; set; } + + [JsonIgnore] + public string TagsText + { + get { return JsonConvert.SerializeObject(Tags, Formatting.Indented); } + } + + // Gets or sets Fault Domain count. + public int? PlatformFaultDomainCount { get; set; } + + // Gets or sets Update Domain count. + public int? PlatformUpdateDomainCount { get; set; } + + // Gets or sets the resource status information. + public IList Statuses { get; set; } + + [JsonIgnore] + public string StatusesText + { + get { return JsonConvert.SerializeObject(Statuses, Formatting.Indented); } + } + + // Gets or sets a list containing reference to all Virtual Machines created under this Availability Set. + public IList VirtualMachinesReferences { get; set; } + + [JsonIgnore] + public string VirtualMachinesReferencesText + { + get { return JsonConvert.SerializeObject(VirtualMachinesReferences, Formatting.Indented); } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSComputeLongRunningOperation.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSComputeLongRunningOperation.cs new file mode 100644 index 000000000000..1ca297dc744e --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSComputeLongRunningOperation.cs @@ -0,0 +1,52 @@ +// +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using Microsoft.Azure.Management.Compute.Models; +using Newtonsoft.Json; +using System; +using System.Net; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSComputeLongRunningOperation + { + public string TrackingOperationId { get; set; } + + public string RequestId { get; set; } + + public ComputeOperationStatus Status { get; set; } + + public HttpStatusCode StatusCode { get; set; } + + public string Output { get; set; } + + public DateTimeOffset StartTime { get; set; } + + public DateTimeOffset? EndTime { get; set; } + + public ApiError Error { get; set; } + + [JsonIgnore] + public string ErrorText + { + get + { + var errorStr = JsonConvert.SerializeObject(Error, Formatting.Indented); + return String.IsNullOrEmpty(errorStr) || "null".Equals(errorStr) ? "" : errorStr; + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSOperation.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSOperation.cs new file mode 100644 index 000000000000..e18ad3c76165 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSOperation.cs @@ -0,0 +1,32 @@ +// +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// Warning: This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the +// code is regenerated. + +using System.Net; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSOperation + { + public string RequestId { get; set; } + + public HttpStatusCode StatusCode { get; set; } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSUsage.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSUsage.cs new file mode 100644 index 000000000000..426c4fe374e8 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSUsage.cs @@ -0,0 +1,55 @@ +// +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// Warning: This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the +// code is regenerated. + +using Microsoft.Azure.Management.Compute.Models; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSUsage : PSOperation + { + // Gets or sets the current value of the usage. + public int CurrentValue { get; set; } + + // Gets or sets the limit of usage. + public uint Limit { get; set; } + + // Gets or sets the name of the type of usage. + public UsageName Name { get; set; } + + [JsonIgnore] + public string NameText + { + get { return JsonConvert.SerializeObject(Name, Formatting.Indented); } + } + + // Gets or sets an enum describing the unit of measurement. + public UsageUnit Unit { get; set; } + + [JsonIgnore] + public string UnitText + { + get { return JsonConvert.SerializeObject(Unit, Formatting.Indented); } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachine.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachine.cs new file mode 100644 index 000000000000..e5be5900dc62 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachine.cs @@ -0,0 +1,178 @@ +// +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// Warning: This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the +// code is regenerated. + +using Microsoft.Azure.Management.Compute.Models; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSVirtualMachine : PSOperation + { + // Gets or sets the property of 'ResourceGroupName' + public string ResourceGroupName + { + get + { + if (string.IsNullOrEmpty(Id)) return null; + Regex r = new Regex(@"(.*?)/resourcegroups/(?\S+)/providers/(.*?)", RegexOptions.IgnoreCase); + Match m = r.Match(Id); + return m.Success ? m.Groups["rgname"].Value : null; + } + } + + // Gets or sets the property of 'Id' + public string Id { get; set; } + + // Gets or sets the property of 'Name' + public string Name { get; set; } + + // Gets or sets the property of 'Type' + public string Type { get; set; } + + // Gets or sets the property of 'Location' + public string Location { get; set; } + + // Gets or sets the property of 'Tags' + public IDictionary Tags { get; set; } + + [JsonIgnore] + public string TagsText + { + get { return JsonConvert.SerializeObject(Tags, Formatting.Indented); } + } + + // Gets or sets the reference Id of the availailbity set to which this virtual machine belongs. + public SubResource AvailabilitySetReference { get; set; } + + [JsonIgnore] + public string AvailabilitySetReferenceText + { + get { return JsonConvert.SerializeObject(AvailabilitySetReference, Formatting.Indented); } + } + + // Gets or sets the diagnostics profile. + public DiagnosticsProfile DiagnosticsProfile { get; set; } + + [JsonIgnore] + public string DiagnosticsProfileText + { + get { return JsonConvert.SerializeObject(DiagnosticsProfile, Formatting.Indented); } + } + + // Gets the virtual machine child extension resources. + public IList Extensions { get; set; } + + [JsonIgnore] + public string ExtensionsText + { + get { return JsonConvert.SerializeObject(Extensions, Formatting.Indented); } + } + + // Gets or sets the hardware profile. + public HardwareProfile HardwareProfile { get; set; } + + [JsonIgnore] + public string HardwareProfileText + { + get { return JsonConvert.SerializeObject(HardwareProfile, Formatting.Indented); } + } + + // Gets the virtual machine instance view. + public VirtualMachineInstanceView InstanceView { get; set; } + + [JsonIgnore] + public string InstanceViewText + { + get { return JsonConvert.SerializeObject(InstanceView, Formatting.Indented); } + } + + // Gets or sets the network profile. + public NetworkProfile NetworkProfile { get; set; } + + [JsonIgnore] + public string NetworkProfileText + { + get { return JsonConvert.SerializeObject(NetworkProfile, Formatting.Indented); } + } + + // Gets or sets the OS profile. + public OSProfile OSProfile { get; set; } + + [JsonIgnore] + public string OSProfileText + { + get { return JsonConvert.SerializeObject(OSProfile, Formatting.Indented); } + } + + // Gets or sets the purchase plan when deploying virtual machine from VM Marketplace images. + public Plan Plan { get; set; } + + [JsonIgnore] + public string PlanText + { + get { return JsonConvert.SerializeObject(Plan, Formatting.Indented); } + } + + // Gets or sets the provisioning state, which only appears in the response. + public string ProvisioningState { get; set; } + + // Gets or sets the storage profile. + public StorageProfile StorageProfile { get; set; } + + [JsonIgnore] + public string StorageProfileText + { + get { return JsonConvert.SerializeObject(StorageProfile, Formatting.Indented); } + } + + [JsonIgnore] + public string[] DataDiskNames + { + get + { + if (this.StorageProfile == null) return null; + var listStr = new List(); + foreach (var item in StorageProfile.DataDisks) + { + listStr.Add(item.Name); + } + return listStr.ToArray(); + } + } + + [JsonIgnore] + public string[] NetworkInterfaceIDs + { + get + { + if (this.NetworkProfile == null) return null; + var listStr = new List(); + foreach (var item in NetworkProfile.NetworkInterfaces) + { + listStr.Add(item.Id); + } + return listStr.ToArray(); + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineExtension.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineExtension.cs new file mode 100644 index 000000000000..2fd6f250ea63 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineExtension.cs @@ -0,0 +1,80 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.Compute.Models; +using System.Collections.Generic; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSVirtualMachineExtension + { + public string ResourceGroupName { get; set; } + + public string Name { get; set; } + + public string Location { get; set; } + + public string Etag { get; set; } + + public string Publisher { get; set; } + + public string ExtensionType { get; set; } + + public string TypeHandlerVersion { get; set; } + + public string Id { get; set; } + + public string PublicSettings { get; set; } + + public string ProtectedSettings { get; set; } + + public string ProvisioningState { get; set; } + + public IList Statuses { get; set; } + } + + public static class PSVirtualMachineExtensionConversions + { + /*public static PSVirtualMachineExtension ToPSVirtualMachineExtension(this VirtualMachineExtensionGetResponse response, string rgName = null) + { + if (response == null) + { + return null; + } + + return response.VirtualMachineExtension.ToPSVirtualMachineExtension(rgName); + }*/ + + public static PSVirtualMachineExtension ToPSVirtualMachineExtension(this VirtualMachineExtension ext, string rgName = null) + { + PSVirtualMachineExtension result = new PSVirtualMachineExtension + { + ResourceGroupName = rgName, + Name = ext.Name, + Location = ext.Location, + Etag = null, // TODO: Update CRP library for this field + Publisher = ext == null ? null : ext.Publisher, + ExtensionType = ext == null ? null : ext.VirtualMachineExtensionType, + TypeHandlerVersion = ext == null ? null : ext.TypeHandlerVersion, + Id = ext.Id, + PublicSettings = ext == null ? null : ext.ProtectedSettings.ToString(), + ProtectedSettings = ext == null ? null : ext.ProtectedSettings.ToString(), + ProvisioningState = ext == null ? null : ext.ProvisioningState, + Statuses = ext == null || ext.InstanceView == null ? null : ext.InstanceView.Statuses + }; + + return result; + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineExtensionImage.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineExtensionImage.cs new file mode 100644 index 000000000000..831df31574d1 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineExtensionImage.cs @@ -0,0 +1,43 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSVirtualMachineExtensionImageType : PSVirtualMachineImageResource + { + public string PublisherName { get; set; } + + public string Type { get; set; } + } + + public class PSVirtualMachineExtensionImage : PSVirtualMachineExtensionImageType + { + public string Version { get; set; } + + public string FilterExpression { get; set; } + } + + public class PSVirtualMachineExtensionImageDetails : PSVirtualMachineExtensionImage + { + public string HandlerSchema { get; set; } + + public string OperatingSystem { get; set; } + + public string ComputeRole { get; set; } + + public bool? SupportsMultipleExtensions { get; set; } + + public bool? VMScaleSetEnabled { get; set; } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineImage.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineImage.cs new file mode 100644 index 000000000000..7e810206fca6 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineImage.cs @@ -0,0 +1,79 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.Compute.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSVirtualMachineImageBase : PSOperation + { + public string Id { get; set; } + + public string Location { get; set; } + } + + public class PSVirtualMachineImagePublisher : PSVirtualMachineImageBase + { + + public string PublisherName { get; set; } + } + + public class PSVirtualMachineImageOffer : PSVirtualMachineImagePublisher + { + public string Offer { get; set; } + } + + public class PSVirtualMachineImageSku : PSVirtualMachineImageOffer + { + public string Skus { get; set; } + } + + public class PSVirtualMachineImage : PSVirtualMachineImageSku + { + public string Version { get; set; } + + public string FilterExpression { get; set; } + } + + public class PSVirtualMachineImageDetail : PSVirtualMachineImage + { + public string Name { get; set; } + + public OSDiskImage OSDiskImage { get; set; } + + [JsonIgnore] + public string OSDiskImageText + { + get { return JsonConvert.SerializeObject(OSDiskImage, Formatting.Indented); } + } + + public PurchasePlan PurchasePlan { get; set; } + + [JsonIgnore] + public string PurchasePlanText + { + get { return JsonConvert.SerializeObject(PurchasePlan, Formatting.Indented); } + } + + public IList DataDiskImages { get; set; } + + [JsonIgnore] + public string DataDiskImagesText + { + get { return JsonConvert.SerializeObject(DataDiskImages, Formatting.Indented); } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineImageResource.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineImageResource.cs new file mode 100644 index 000000000000..fe108b57e964 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineImageResource.cs @@ -0,0 +1,40 @@ +// +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// Warning: This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the +// code is regenerated. + +using Microsoft.Azure.Management.Compute.Models; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSVirtualMachineImageResource : PSOperation + { + // Gets or sets the ID of the artifact. + public string Id { get; set; } + + // Gets or sets the location of the resource. + public string Location { get; set; } + + // Gets or sets the name of the resource. + public string Name { get; set; } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineInstanceView.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineInstanceView.cs new file mode 100644 index 000000000000..ab7a29c3fccd --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineInstanceView.cs @@ -0,0 +1,111 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.Compute.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSVirtualMachineInstanceView + { + public string ResourceGroupName { get; set; } + + public string Name { get; set; } + + public BootDiagnosticsInstanceView BootDiagnostics { get; set; } + + [JsonIgnore] + public string BootDiagnosticsText + { + get { return JsonConvert.SerializeObject(BootDiagnostics, Formatting.Indented); } + } + + public IList Disks { get; set; } + + [JsonIgnore] + public string DisksText + { + get { return JsonConvert.SerializeObject(Disks, Formatting.Indented); } + } + + public IList Extensions { get; set; } + + [JsonIgnore] + public string ExtensionsText + { + get { return JsonConvert.SerializeObject(Extensions, Formatting.Indented); } + } + + public int? PlatformFaultDomain { get; set; } + + public int? PlatformUpdateDomain { get; set; } + + public string RemoteDesktopThumbprint { get; set; } + + public VirtualMachineAgentInstanceView VMAgent { get; set; } + + [JsonIgnore] + public string VMAgentText + { + get { return JsonConvert.SerializeObject(VMAgent, Formatting.Indented); } + } + + public IList Statuses { get; set; } + + [JsonIgnore] + public string StatusesText + { + get { return JsonConvert.SerializeObject(Statuses, Formatting.Indented); } + } + } + + public static class PSVirtualMachineInstanceViewExtension + { + public static PSVirtualMachineInstanceView ToPSVirtualMachineInstanceView( + this VirtualMachineInstanceView virtualMachineInstanceView, + string resourceGroupName = null, + string vmName = null) + { + PSVirtualMachineInstanceView result = new PSVirtualMachineInstanceView + { + ResourceGroupName = resourceGroupName, + Name = vmName, + BootDiagnostics = virtualMachineInstanceView.BootDiagnostics, + Disks = virtualMachineInstanceView.Disks, + Extensions = virtualMachineInstanceView.Extensions, + Statuses = virtualMachineInstanceView.Statuses, + PlatformFaultDomain = virtualMachineInstanceView.PlatformFaultDomain, + PlatformUpdateDomain = virtualMachineInstanceView.PlatformUpdateDomain, + RemoteDesktopThumbprint = virtualMachineInstanceView.RdpThumbPrint, + VMAgent = virtualMachineInstanceView.VmAgent + }; + + return result; + } + + public static PSVirtualMachineInstanceView ToPSVirtualMachineInstanceView( + this VirtualMachine response, + string resourceGroupName = null, + string vmName = null) + { + if (response == null) + { + return null; + } + + return response.InstanceView == null ? null : response.InstanceView.ToPSVirtualMachineInstanceView(resourceGroupName, vmName); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineSize.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineSize.cs new file mode 100644 index 000000000000..63f1a5e212e2 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineSize.cs @@ -0,0 +1,49 @@ +// +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// Warning: This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the +// code is regenerated. + +using Microsoft.Azure.Management.Compute.Models; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSVirtualMachineSize : PSOperation + { + // Gets or sets the Maximum number of data disks allowed by a VM size. + public int? MaxDataDiskCount { get; set; } + + // Gets or sets the Memory size supported by a VM size. + public int MemoryInMB { get; set; } + + // Gets or sets the VM size name. + public string Name { get; set; } + + // Gets or sets the Number of cores supported by a VM size. + public int NumberOfCores { get; set; } + + // Gets or sets the OS disk size allowed by a VM size. + public int OSDiskSizeInMB { get; set; } + + // Gets or sets the Resource disk size allowed by a VM size. + public int ResourceDiskSizeInMB { get; set; } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/VhdDownloadContext.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/VhdDownloadContext.cs new file mode 100644 index 000000000000..6b460684400e --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/VhdDownloadContext.cs @@ -0,0 +1,25 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.IO; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class VhdDownloadContext + { + public FileInfo LocalFilePath { get; set; } + public Uri Source { get; set; } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Models/VhdUploadContext.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Models/VhdUploadContext.cs new file mode 100644 index 000000000000..bbdd61a3a514 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Models/VhdUploadContext.cs @@ -0,0 +1,25 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.IO; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class VhdUploadContext + { + public FileInfo LocalFilePath { get; set; } + public Uri DestinationUri { get; set; } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Properties/AssemblyInfo.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..6c9ad26fe766 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Properties/AssemblyInfo.cs @@ -0,0 +1,34 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Microsoft Azure Powershell - Compute Resource Provider")] +[assembly: AssemblyCompany(Microsoft.Azure.Commands.Common.AzurePowerShell.AssemblyCompany)] +[assembly: AssemblyProduct(Microsoft.Azure.Commands.Common.AzurePowerShell.AssemblyProduct)] +[assembly: AssemblyCopyright(Microsoft.Azure.Commands.Common.AzurePowerShell.AssemblyCopyright)] + +[assembly: ComVisible(false)] +[assembly: CLSCompliant(false)] +[assembly: Guid("91792853-487B-4DC2-BE6C-DD09A0A1BC10")] +[assembly: AssemblyVersion(Microsoft.Azure.Commands.Common.AzurePowerShell.AssemblyVersion)] +[assembly: AssemblyFileVersion(Microsoft.Azure.Commands.Common.AzurePowerShell.AssemblyFileVersion)] +#if SIGN +[assembly: InternalsVisibleTo("Microsoft.Azure.Commands.Compute.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] +#else +[assembly: InternalsVisibleTo("Microsoft.Azure.Commands.Compute.Test")] +#endif \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Properties/Resources.Designer.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Properties/Resources.Designer.cs new file mode 100644 index 000000000000..9cabaca11d5b --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Microsoft.Azure.Commands.Compute.Properties { + using System; + using System.Reflection; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Azure.Commands.Compute.Properties.Resources", typeof(Resources).GetTypeInfo().Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Test. + /// + internal static string Test { + get { + return ResourceManager.GetString("Test", resourceCulture); + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Properties/Resources.resx b/src/CLU/Microsoft.Azure.Commands.Compute/Properties/Resources.resx new file mode 100644 index 000000000000..e5a9d0021a93 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Properties/Resources.resx @@ -0,0 +1,378 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Availability set removal operation + + + This cmdlet will remove the specified availability set. Do you want to continue? + + + Cannot specify both Windows and Linux configurations. + + + No Run File has been assigned, and the Custom Script extension will try to use the first specified File Name as the Run File. + + + Virtual machine extension removal operation + + + This cmdlet will remove the specified virtual machine extension. Do you want to continue? + + + The RDP file cannot be generated because the network interface of the virtual machine does not reference a PublicIP or an InboundNatRule of a public load balancer. + + + The RDP file cannot be generated because the network interface of the virtual machine does not reference an InboundNatRule of a public load balancer. + + + The RDP file cannot be generated because the network interface of the virtual machine does not reference a PublicIP or an InboungNatRule of the load balancer. + + + Virtual machine removal operation + + + This cmdlet will remove the specified virtual machine. Do you want to continue? + + + Virtual machine stopping operation + + + This cmdlet will stop the specified virtual machine. Do you want to continue? + + + Cannot find configuration data file: {0} + + + The -ConfigurationArchive parameter must no include a path + + + The configuration data must be a .psd1 file + + + Please enter a valid DSC Extension version. Allowed format: N.N where N = [1..9] + + + Cannot find configuration file: {0}. + 0 = path to the configuration file + + + Invalid configuration file: {0}. +The file needs to be a PowerShell script (.ps1 or .psm1) or a ZIP archive (.zip). + 0 = path to the configuration file + + + Configuration file '{0}' not found. + 0 = path to the configuration file + + + Cannot get module for DscResource '{0}'. Possible solutions: +1) Specify -ModuleName for Import-DscResource in your configuration. +2) Unblock module that contains resource. +3) Move Import-DscResource inside Node block. + + 0 = name of DscResource + + + Configuration script '{0}' contained parse errors: +{1} + 0 = path to the configuration script, 1 = parser errors + + + The storage context must include an storage account. + + + Apply configuration '{0}' + {0} is the name of a PowerShell DSC Configuration function + + + Parsing configuration script: {0} + {0} is the path to a script file + + + Storage Blob '{0}' already exists. Use the -Force parameter to overwrite it. + {0} is the name of an storage blob + + + Upload '{0}' + {0} is the name of an storage blob + + + Invalid configuration file: {0}. +The file needs to be a PowerShell script (.ps1 or .psm1). + 0 = path to the configuration file + + + If the ConfigurationArchive argument is null, then the ConfigurationName, ConfigurationArgument, and ConfigurationDataPath parameters must not be specified + + + If the ConfigurationArchive argument is null, then the StorageContext, ArchiveContainerName, and ArchiveStorageEndpointSuffix parameters must not be specified + + + Create Archive + + + File '{0}' already exists. Use the -Force parameter to overwrite it. + {0} is the path to a file + + + Your current PowerShell version {1} is less then required by this cmdlet {0}. Consider download and install latest PowerShell version. + {0} = minimal required PS version, {1} = current PS version + + + Can not find your azure storage credential. Please specify an storage context using the -StorageContext parameter, or set the current storage account using "Set-AzureRmSubscription", or set the "AZURE_STORAGE_CONNECTION_STRING" environment variable. + + + List of required modules: [{0}]. + {0} = list of modules + + + Temp folder '{0}' created. + {0} = temp folder path + + + Copy '{0}' to '{1}'. + {0} = source, {1} = destination + + + Copy the module '{0}' to '{1}'. + {0} = source, {1} = destination + + + Create a zip file '{0}' from directory '{1}'. + {0} = target zip, {1} = source + + + Deleted '{0}' + {0} is the path of a file + + + Cannot delete '{0}': {1} + {0} is the path of a file, {1} is an error message + + + Cannot deserialize settings string from DSC extension. Updating your Azure PowerShell SDK to the latest version may solve this problem. Settings string: +{0} + {0} settings json string + + + Configuration published to {0} + {0} is an URI + + + Remove Extension + + + {0} + + + SAS Uri for the destination blob is not supported in patch mode:{0} + + + Calculating MD5 Hash + + + MD5 hash is being calculated for the file '{0}'. + + + Copying + + + Creating new page blob of size {0}... + + + Detecting the empty data blocks in the local file. + + + Detecting the empty data blocks completed. + + + Downloading + + + Elapsed time for copy: {0} + + + Elapsed time for download: {0} + + + Elapsed time for the operation: {0} + + + Elapsed time for upload: {0} + + + Empty block detected: {0} + + + Completed + + + Detecting empty blocks + + + {0} days {1:00}:{2:00}:{3:00} + + + {0:0.0}% complete; Remaining Time: {1}; Throughput: {2:0.0}Mbps + + + Completed + + + MD5 hash calculation is completed. + + + Range of the block is {0}, Length: {1} + + + Empty Block Detection + + + Found existing page blob. Resuming upload... + + + Network disruption occured, retrying. + + + Upload failed with exceptions: + + + Uploading + + + No current subscription has been designated. Use Select-AzureRmSubscription -Current <subscriptionName> to set the current subscription. + + + A data disk, {0}, is not currently assigned for this VM. Use Add-AzureRmVMDataDisk to add it. + + + Cannot deserialize settings string from Sql Server extension. Updating your Azure PowerShell SDK to the latest version may solve this problem. Settings string: +{0} + {0} settings json string + + + Path '{0}' not found. + 0 = path to the additional content file/directory + + + Configuration published to {0} + {0} is an URI + + \ No newline at end of file diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/RemoteDesktop/GetAzureRemoteDesktopFileCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/RemoteDesktop/GetAzureRemoteDesktopFileCommand.cs new file mode 100644 index 000000000000..67554b61da70 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/RemoteDesktop/GetAzureRemoteDesktopFileCommand.cs @@ -0,0 +1,239 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +// TODO: NRP +// +//using System; +//using System.Diagnostics; +//using System.IO; +//using System.Linq; +//using System.Management.Automation; +//using Microsoft.Azure.Commands.Compute.Common; +//using Microsoft.Azure.Management.Compute; +//using Microsoft.Azure.Management.Network; + +//namespace Microsoft.Azure.Commands.Compute +//{ +// [Cmdlet(VerbsCommon.Get, ProfileNouns.RemoteDesktopFile)] +// public class GetAzureRemoteDesktopFileCommand : VirtualMachineRemoteDesktopBaseCmdlet +// { +// [Parameter( +// Mandatory = true, +// Position = 0, +// ValueFromPipelineByPropertyName = true, +// HelpMessage = "The resource group name.")] +// [ValidateNotNullOrEmpty] +// public string ResourceGroupName { get; set; } + +// [Alias("ResourceName", "VMName")] +// [Parameter( +// Mandatory = true, +// Position = 1, +// ValueFromPipelineByPropertyName = true, +// HelpMessage = "The resource name.")] +// [ValidateNotNullOrEmpty] +// public string Name { get; set; } + +// [Parameter( +// Mandatory = true, +// Position = 2, +// ValueFromPipelineByPropertyName = true, +// HelpMessage = "Path and name of the output RDP file.", +// ParameterSetName = "Download")] +// [Parameter( +// Mandatory = false, +// Position = 2, +// ValueFromPipelineByPropertyName = true, +// HelpMessage = "Path and name of the output RDP file.", +// ParameterSetName = "Launch")] +// [ValidateNotNullOrEmpty] +// public string LocalPath { get; set; } + +// [Parameter( +// Mandatory = true, +// Position = 3, +// HelpMessage = "Start a remote desktop session to the specified role instance.", +// ParameterSetName = "Launch")] +// public SwitchParameter Launch +// { +// get; +// set; +// } + +// protected override void ProcessRecord() +// { +// base.ProcessRecord(); + +// ExecuteClientAction(() => +// { +// const string fullAddressPrefix = "full address:s:"; +// const string promptCredentials = "prompt for credentials:i:1"; +// const int defaultPort = 3389; + +// string address = string.Empty; +// int port = defaultPort; + +// // Get Azure VM +// var vmResponse = this.VirtualMachineClient.Get(this.ResourceGroupName, this.Name); + +// // Get the NIC +// var nicResourceGroupName = +// this.GetResourceGroupName(vmResponse.VirtualMachine.NetworkProfile.NetworkInterfaces.First().ReferenceUri); + +// var nicName = +// this.GetResourceName( +// vmResponse.VirtualMachine.NetworkProfile.NetworkInterfaces.First().ReferenceUri, "networkInterfaces"); + +// var nicResponse = +// this.NetworkClient.NetworkResourceProviderClient.NetworkInterfaces.Get(nicResourceGroupName, nicName); + +// if (nicResponse.NetworkInterface.IpConfigurations.First().PublicIpAddress != null && !string.IsNullOrEmpty(nicResponse.NetworkInterface.IpConfigurations.First().PublicIpAddress.Id)) +// { +// // Get PublicIPAddress resource if present +// address = this.GetAddressFromPublicIPResource(nicResponse.NetworkInterface.IpConfigurations.First().PublicIpAddress.Id); +// } +// else if (nicResponse.NetworkInterface.IpConfigurations.First().LoadBalancerInboundNatRules.Any()) +// { +// address = string.Empty; + +// // Get ipaddress and port from loadbalancer +// foreach (var nicRuleRef in nicResponse.NetworkInterface.IpConfigurations.First().LoadBalancerInboundNatRules) +// { +// var lbName = this.GetResourceName(nicRuleRef.Id, "loadBalancers"); +// var lbResourceGroupName = this.GetResourceGroupName(nicRuleRef.Id); + +// var loadbalancer = +// this.NetworkClient.NetworkResourceProviderClient.LoadBalancers.Get(lbResourceGroupName, lbName).LoadBalancer; + +// // Iterate over the InboundNatRules where Backendport = 3389 +// var inboundRule = +// loadbalancer.InboundNatRules.Where( +// rule => +// rule.BackendPort == defaultPort +// && string.Equals( +// rule.Id, +// nicRuleRef.Id, +// StringComparison.OrdinalIgnoreCase)); + +// if (inboundRule.Any()) +// { +// port = inboundRule.First().FrontendPort; + +// // Get the corresponding frontendIPConfig -> publicIPAddress +// var frontendIPConfig = +// loadbalancer.FrontendIpConfigurations.First( +// frontend => +// string.Equals( +// inboundRule.First().FrontendIPConfiguration.Id, +// frontend.Id, +// StringComparison.OrdinalIgnoreCase)); + +// if (frontendIPConfig.PublicIpAddress != null) +// { +// address = this.GetAddressFromPublicIPResource(frontendIPConfig.PublicIpAddress.Id); +// break; +// } +// } +// } + +// if (string.IsNullOrEmpty(address)) +// { +// throw new ArgumentException(Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineNotAssociatedWithPublicLoadBalancer); +// } +// } +// else +// { +// throw new ArgumentException(Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineNotAssociatedWithPublicIPOrPublicLoadBalancer); +// } + +// // Write to file +// string rdpFilePath = this.LocalPath ?? Path.GetTempFileName(); + +// using (var file = new StreamWriter(rdpFilePath)) +// { +// file.WriteLine(fullAddressPrefix + address + ":" + port); +// file.WriteLine(promptCredentials); +// } + +// if (Launch.IsPresent) +// { +// var startInfo = new ProcessStartInfo +// { +// CreateNoWindow = true, +// WindowStyle = ProcessWindowStyle.Hidden +// }; + +// if (this.LocalPath == null) +// { +// string scriptGuid = Guid.NewGuid().ToString(); + +// string launchRDPScript = Path.GetTempPath() + scriptGuid + ".bat"; +// using (var scriptStream = File.OpenWrite(launchRDPScript)) +// { +// var writer = new StreamWriter(scriptStream); +// writer.WriteLine("start /wait mstsc.exe " + rdpFilePath); +// writer.Flush(); +// } + +// startInfo.FileName = launchRDPScript; +// } +// else +// { +// startInfo.FileName = "mstsc.exe"; +// startInfo.Arguments = rdpFilePath; +// } + +// Process.Start(startInfo); +// } +// }); +// } + +// private string GetAddressFromPublicIPResource(string resourceId) +// { +// string address = string.Empty; + +// // Get IpAddress from public IPAddress resource +// var publicIPResourceGroupName = this.GetResourceGroupName(resourceId); +// var publicIPName = this.GetResourceName(resourceId, "publicIPAddresses"); + +// var publicIpResponse = +// this.NetworkClient.NetworkResourceProviderClient.PublicIpAddresses.Get( +// publicIPResourceGroupName, +// publicIPName); + + +// // Use the FQDN if present +// if (publicIpResponse.PublicIpAddress.DnsSettings != null +// && !string.IsNullOrEmpty(publicIpResponse.PublicIpAddress.DnsSettings.Fqdn)) +// { +// address = publicIpResponse.PublicIpAddress.DnsSettings.Fqdn; +// } +// else +// { +// address = publicIpResponse.PublicIpAddress.IpAddress; +// } + +// return address; +// } +// private string GetResourceGroupName(string resourceId) +// { +// return resourceId.Split('/')[4]; +// } + +// private string GetResourceName(string resourceId, string resource) +// { +// return resourceId.Split('/')[8]; +// } +// } +//} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/RemoteDesktop/VirtualMachineRemoteDesktopBaseCmdlet.cs b/src/CLU/Microsoft.Azure.Commands.Compute/RemoteDesktop/VirtualMachineRemoteDesktopBaseCmdlet.cs new file mode 100644 index 000000000000..f052fadd8ba6 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/RemoteDesktop/VirtualMachineRemoteDesktopBaseCmdlet.cs @@ -0,0 +1,45 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +// TODO: NRP +// +//using Microsoft.Azure.Commands.Network; + +//namespace Microsoft.Azure.Commands.Compute +//{ +// public class VirtualMachineRemoteDesktopBaseCmdlet : VirtualMachineBaseCmdlet +// { + +// private NetworkClient networkClient; + +// public NetworkClient NetworkClient +// { +// get +// { +// if (networkClient == null) +// { +// networkClient = new NetworkClient(ClientFactory, DefaultProfile.Context) +// { +// VerboseLogger = WriteVerboseWithTimestamp, +// ErrorLogger = WriteErrorWithTimestamp, +// WarningLogger = WriteWarningWithTimestamp +// }; +// } +// return networkClient; +// } + +// set { networkClient = value; } +// } +// } +//} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/AddAzureVhdCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/AddAzureVhdCommand.cs new file mode 100644 index 000000000000..4411cecccca3 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/AddAzureVhdCommand.cs @@ -0,0 +1,177 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +// TODO: Rewrite for removing Sync +//using Microsoft.Azure.Commands.Compute.Common; +//using Microsoft.Azure.Commands.Compute.Models; +//using Microsoft.Azure.Common.Authentication; +//using Microsoft.Azure.Common.Authentication.Models; +//using Microsoft.WindowsAzure.Commands.Sync.Download; +//using System; +//using System.IO; +//using System.Management.Automation; +//using Rsrc = Microsoft.Azure.Commands.Compute.Properties.Resources; +//using Microsoft.Azure.Management.Storage; +//using Microsoft.Azure.Commands.ResourceManager.Common; + +//namespace Microsoft.Azure.Commands.Compute.StorageServices +//{ +// /// +// /// Uploads a vhd as fixed disk format vhd to a blob in Microsoft Azure Storage +// /// +// [Cmdlet(VerbsCommon.Add, ProfileNouns.Vhd), OutputType(typeof(VhdUploadContext))] +// public class AddAzureVhdCommand : ComputeClientBaseCmdlet +// { +// private const int DefaultNumberOfUploaderThreads = 8; + +// [Parameter( +// Position = 0, +// Mandatory = false, +// ValueFromPipelineByPropertyName = true)] +// [ValidateNotNullOrEmpty] +// public string ResourceGroupName { get; set; } + +// [Parameter( +// Position = 1, +// Mandatory = true, +// ValueFromPipelineByPropertyName = true, +// HelpMessage = "Uri to blob")] +// [ValidateNotNullOrEmpty] +// [Alias("dst")] +// public Uri Destination +// { +// get; +// set; +// } + +// [Parameter( +// Position = 2, +// Mandatory = true, +// ValueFromPipelineByPropertyName = true, +// HelpMessage = "Local path of the vhd file")] +// [ValidateNotNullOrEmpty] +// [Alias("lf")] +// public FileInfo LocalFilePath +// { +// get; +// set; +// } + +// [Parameter( +// Position = 3, +// Mandatory = false, +// ValueFromPipelineByPropertyName = true, +// HelpMessage = "Number of uploader threads")] +// [ValidateNotNullOrEmpty] +// [ValidateRange(1, 64)] +// [Alias("th")] +// public int? NumberOfUploaderThreads +// { +// get; +// set; +// } + +// [Parameter( +// Position = 4, +// Mandatory = false, +// ValueFromPipelineByPropertyName = true, +// HelpMessage = "Uri to a base image in a blob storage account to apply the difference")] +// [ValidateNotNullOrEmpty] +// [Alias("bs")] +// public Uri BaseImageUriToPatch +// { +// get; +// set; +// } + +// [Parameter( +// Position = 5, +// Mandatory = false, +// ValueFromPipelineByPropertyName = true, +// ParameterSetName="Vhd", +// HelpMessage = "Delete the blob if already exists")] +// [ValidateNotNullOrEmpty] +// [Alias("o")] +// public SwitchParameter OverWrite +// { +// get; +// set; +// } + +// public UploadParameters ValidateParameters() +// { +// BlobUri destinationUri; +// if (!BlobUri.TryParseUri(Destination, out destinationUri)) +// { +// throw new ArgumentOutOfRangeException("Destination", this.Destination.ToString()); +// } + +// BlobUri baseImageUri = null; +// if (this.BaseImageUriToPatch != null) +// { +// if (!BlobUri.TryParseUri(BaseImageUriToPatch, out baseImageUri)) +// { +// throw new ArgumentOutOfRangeException("BaseImageUriToPatch", this.BaseImageUriToPatch.ToString()); +// } + +// if (!String.IsNullOrEmpty(destinationUri.Uri.Query)) +// { +// var message = String.Format(Rsrc.AddAzureVhdCommandSASUriNotSupportedInPatchMode, destinationUri.Uri); +// throw new ArgumentOutOfRangeException("Destination", message); +// } +// } + +// var storageCredentialsFactory = CreateStorageCredentialsFactory(); + +// PathIntrinsics currentPath = SessionState.Path; +// var filePath = new FileInfo(currentPath.GetUnresolvedProviderPathFromPSPath(LocalFilePath.ToString())); + +// var parameters = new UploadParameters( +// destinationUri, baseImageUri, filePath, OverWrite.IsPresent, +// (NumberOfUploaderThreads) ?? DefaultNumberOfUploaderThreads) +// { +// Cmdlet = this, +// BlobObjectFactory = new CloudPageBlobObjectFactory(storageCredentialsFactory, TimeSpan.FromMinutes(1)) +// }; + +// return parameters; +// } + +// private StorageCredentialsFactory CreateStorageCredentialsFactory() +// { +// StorageCredentialsFactory storageCredentialsFactory; + +// var storageClient = AzureSession.ClientFactory.CreateClient( +// DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager); + +// if (StorageCredentialsFactory.IsChannelRequired(Destination)) +// { +// storageCredentialsFactory = new StorageCredentialsFactory(this.ResourceGroupName, storageClient, DefaultContext.Subscription); +// } +// else +// { +// storageCredentialsFactory = new StorageCredentialsFactory(); +// } + +// return storageCredentialsFactory; +// } + +// protected override void ProcessRecord() +// { +// var parameters = ValidateParameters(); +// var vhdUploadContext = VhdUploaderModel.Upload(parameters); +// WriteObject(vhdUploadContext); +// } +// } +//} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/CloudPageBlobObjectFactory.cs b/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/CloudPageBlobObjectFactory.cs new file mode 100644 index 000000000000..191b0add7960 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/CloudPageBlobObjectFactory.cs @@ -0,0 +1,61 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +// TODO: Rewrite for removing Sync +//using Microsoft.WindowsAzure.Commands.Sync.Download; +//using Microsoft.WindowsAzure.Commands.Sync.Upload; +//using Microsoft.WindowsAzure.Storage.Blob; +//using Microsoft.WindowsAzure.Storage.RetryPolicies; +//using System; + +//namespace Microsoft.Azure.Commands.Compute.StorageServices +//{ +// public class CloudPageBlobObjectFactory : ICloudPageBlobObjectFactory +// { +// private readonly TimeSpan delayBetweenRetries = TimeSpan.FromSeconds(10); +// private readonly StorageCredentialsFactory credentialsFactory; +// private TimeSpan operationTimeout; + + +// public CloudPageBlobObjectFactory(StorageCredentialsFactory credentialsFactory, TimeSpan operationTimeout) +// { +// this.credentialsFactory = credentialsFactory; +// this.operationTimeout = operationTimeout; +// } + +// public CloudPageBlob Create(BlobUri destination) +// { +// return new CloudPageBlob(new Uri(destination.BlobPath), credentialsFactory.Create(destination)); +// } + +// public bool CreateContainer(BlobUri destination) +// { +// if (String.IsNullOrEmpty(destination.Uri.Query)) +// { +// var destinationBlob = Create(destination); +// return destinationBlob.Container.CreateIfNotExists(this.CreateRequestOptions()); +// } +// return true; +// } + +// public BlobRequestOptions CreateRequestOptions() +// { +// return new BlobRequestOptions +// { +// ServerTimeout = this.operationTimeout, +// RetryPolicy = new LinearRetry(delayBetweenRetries, 5) +// }; +// } +// } +//} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/SaveAzureVhdCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/SaveAzureVhdCommand.cs new file mode 100644 index 000000000000..70d146208ce8 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/SaveAzureVhdCommand.cs @@ -0,0 +1,147 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- +// TODO: Rewrite for removing Sync +//using Microsoft.Azure.Commands.Compute.Common; +//using Microsoft.Azure.Commands.Compute.Models; +//using Microsoft.Azure.Common.Authentication; +//using Microsoft.Azure.Common.Authentication.Models; +//using Microsoft.Azure.Management.Storage; +//using Microsoft.WindowsAzure.Commands.Sync.Download; +//using System; +//using System.IO; +//using System.Management.Automation; + +//namespace Microsoft.Azure.Commands.Compute.StorageServices +//{ +// [Cmdlet(VerbsData.Save, ProfileNouns.Vhd), OutputType(typeof(VhdDownloadContext))] +// public class SaveAzureVhdCommand : ComputeClientBaseCmdlet +// { +// private const int DefaultNumberOfUploaderThreads = 8; +// private const string ResourceGroupParameterSet = "ResourceGroupParameterSetName"; +// private const string StorageKeyParameterSet = "StorageKeyParameterSetName"; + +// [Parameter( +// Position = 0, +// Mandatory = true, +// ParameterSetName = ResourceGroupParameterSet, +// ValueFromPipelineByPropertyName = true)] +// [ValidateNotNullOrEmpty] +// public string ResourceGroupName { get; set; } + +// [Parameter( +// Position = 0, +// Mandatory = true, +// ParameterSetName = StorageKeyParameterSet, +// HelpMessage = "Key of the storage account")] +// [ValidateNotNullOrEmpty] +// [Alias("sk")] +// public string StorageKey { get; set; } + +// [Parameter( +// Position = 1, +// Mandatory = true, +// ValueFromPipelineByPropertyName = true, +// HelpMessage = "Uri to blob")] +// [ValidateNotNullOrEmpty] +// [Alias("src", "Source")] +// public Uri SourceUri { get; set; } + +// [Parameter( +// Position = 2, +// Mandatory = true, +// HelpMessage = "Local path of the vhd file")] +// [ValidateNotNullOrEmpty] +// [Alias("lf")] +// public FileInfo LocalFilePath { get; set; } + +// private int numberOfThreads = DefaultNumberOfUploaderThreads; + +// [Parameter( +// Position = 3, +// Mandatory = false, +// HelpMessage = "Number of downloader threads")] +// [ValidateNotNullOrEmpty] +// [ValidateRange(1, 64)] +// [Alias("th")] +// public int NumberOfThreads +// { +// get { return this.numberOfThreads; } +// set { this.numberOfThreads = value; } +// } + +// [Parameter( +// Position = 4, +// Mandatory = false, +// HelpMessage = "Delete the local file if already exists")] +// [ValidateNotNullOrEmpty] +// [Alias("o")] +// public SwitchParameter OverWrite { get; set; } + +// protected override void ProcessRecord() +// { +// var result = DownloadFromBlobUri( +// this, +// this.SourceUri, +// this.LocalFilePath, +// this.StorageKey, +// this.ResourceGroupName, +// this.NumberOfThreads, +// this.OverWrite); +// WriteObject(result); +// } + + +// private VhdDownloadContext DownloadFromBlobUri( +// ComputeClientBaseCmdlet cmdlet, +// Uri sourceUri, +// FileInfo localFileInfo, +// string storagekey, +// string resourceGroupName, +// int numThreads, +// bool overwrite) +// { +// BlobUri blobUri; +// if (!BlobUri.TryParseUri(sourceUri, out blobUri)) +// { +// throw new ArgumentOutOfRangeException("Source", sourceUri.ToString()); +// } + +// if (storagekey == null) +// { +// var storageClient = AzureSession.ClientFactory.CreateClient( +// DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager); + + +// var storageService = storageClient.StorageAccounts.GetProperties(resourceGroupName, blobUri.StorageAccountName); +// if (storageService != null) +// { +// var storageKeys = storageClient.StorageAccounts.ListKeys(resourceGroupName, storageService.StorageAccount.Name); +// storagekey = storageKeys.StorageAccountKeys.Key1; +// } +// } + +// var downloaderParameters = new DownloaderParameters +// { +// BlobUri = blobUri, +// LocalFilePath = localFileInfo.FullName, +// ConnectionLimit = numThreads, +// StorageAccountKey = storagekey, +// ValidateFreeDiskSpace = true, +// OverWrite = overwrite +// }; + +// return VhdDownloaderModel.Download(downloaderParameters, cmdlet); +// } +// } +//} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/StorageCredentialsFactory.cs b/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/StorageCredentialsFactory.cs new file mode 100644 index 000000000000..1e0b508f3b68 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/StorageCredentialsFactory.cs @@ -0,0 +1,64 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +// TODO: Rewrite for removing Sync +//using Microsoft.Azure.Commands.Common.Authentication.Models; +//using Microsoft.Azure.Common.Authentication.Models; +//using Microsoft.Azure.Management.Storage; +//using Microsoft.WindowsAzure.Commands.Sync.Download; +//using Microsoft.WindowsAzure.Storage.Auth; +//using System; +//using Rsrc = Microsoft.Azure.Commands.Compute.Properties.Resources; + +//namespace Microsoft.Azure.Commands.Compute.StorageServices +//{ +// public class StorageCredentialsFactory +// { +// private StorageManagementClient client; +// private AzureSubscription currentSubscription; +// public string resourceGroupName { get; set; } + +// public static bool IsChannelRequired(Uri destination) +// { +// return String.IsNullOrEmpty(destination.Query); +// } + +// public StorageCredentialsFactory() +// { +// this.resourceGroupName = null; +// } + +// public StorageCredentialsFactory(string resourceGroupName, StorageManagementClient client, AzureSubscription currentSubscription) +// { +// this.resourceGroupName = resourceGroupName; +// this.client = client; +// this.currentSubscription = currentSubscription; +// } + +// public StorageCredentials Create(BlobUri destination) +// { +// if (IsChannelRequired(destination.Uri)) +// { +// if(currentSubscription == null) +// { +// throw new ArgumentException(Rsrc.StorageCredentialsFactoryCurrentSubscriptionNotSet, "SubscriptionId"); +// } +// var storageKeys = this.client.StorageAccounts.ListKeys(this.resourceGroupName, destination.StorageAccountName); +// return new StorageCredentials(destination.StorageAccountName, storageKeys.StorageAccountKeys.Key1); +// } + +// return new StorageCredentials(destination.Uri.Query); +// } +// } +//} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Usage/GetAzureVMUsageCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Usage/GetAzureVMUsageCommand.cs new file mode 100644 index 000000000000..096f22dc61b2 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Usage/GetAzureVMUsageCommand.cs @@ -0,0 +1,55 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using System.Collections.Generic; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineUsage)] + [OutputType(typeof(PSUsage))] + public class GetAzureVMUsageCommand : VirtualMachineUsageBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The location name.")] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + var result = this.UsageClient.List(this.Location.Canonicalize()); + + List psResultList = new List(); + foreach (var item in result) + { + var psItem = Mapper.Map(item); + psResultList.Add(psItem); + } + + WriteObject(psResultList, true); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/Usage/VirtualMachineUsageBaseCmdlet.cs b/src/CLU/Microsoft.Azure.Commands.Compute/Usage/VirtualMachineUsageBaseCmdlet.cs new file mode 100644 index 000000000000..12b882c56102 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/Usage/VirtualMachineUsageBaseCmdlet.cs @@ -0,0 +1,29 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.Compute; + +namespace Microsoft.Azure.Commands.Compute +{ + public abstract class VirtualMachineUsageBaseCmdlet : ComputeClientBaseCmdlet + { + public IUsageOperations UsageClient + { + get + { + return ComputeClient.ComputeManagementClient.Usage; + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/RestartAzureVMCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/RestartAzureVMCommand.cs new file mode 100644 index 000000000000..58b4d4136ca9 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/RestartAzureVMCommand.cs @@ -0,0 +1,45 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsLifecycle.Restart, ProfileNouns.VirtualMachine, DefaultParameterSetName = ResourceGroupNameParameterSet)] + [OutputType(typeof(PSComputeLongRunningOperation))] + public class RestartAzureVMCommand : VirtualMachineActionBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + this.VirtualMachineClient.Restart(this.ResourceGroupName, this.Name); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/SaveAzureVMImageCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/SaveAzureVMImageCommand.cs new file mode 100644 index 000000000000..c566d816e6cb --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/SaveAzureVMImageCommand.cs @@ -0,0 +1,98 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using System.Management.Automation; +using System.IO; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsData.Save, ProfileNouns.VirtualMachineImage, DefaultParameterSetName = ResourceGroupNameParameterSet)] + [OutputType(typeof(PSComputeLongRunningOperation))] + public class SaveAzureVMImageCommand : VirtualMachineActionBaseCmdlet + { + [Alias("VMName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Destination Container Name.")] + [ValidateNotNullOrEmpty] + public string DestinationContainerName { get; set; } + + [Alias("VirtualHardDiskNamePrefix")] + [Parameter( + Mandatory = true, + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Virtual Hard Disk Name Prefix.")] + [ValidateNotNullOrEmpty] + public string VHDNamePrefix { get; set; } + + [Parameter( + Position = 4, + ValueFromPipelineByPropertyName = true, + HelpMessage = "To Overwrite.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Overwrite { get; set; } + + [Parameter( + Position = 5, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The file path in which the template of the captured image is stored")] + [ValidateNotNullOrEmpty] + public string Path { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + var parameters = new VirtualMachineCaptureParameters + { + DestinationContainerName = DestinationContainerName, + OverwriteVhds = Overwrite.IsPresent, + VhdPrefix = VHDNamePrefix + }; + + var op = this.VirtualMachineClient.Capture( + this.ResourceGroupName, + this.Name, + parameters); + + var result = Mapper.Map(op); + + if (!string.IsNullOrWhiteSpace(this.Path)) + { + File.WriteAllText(this.Path, result.Output); + } + + WriteObject(result); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/SetAzureVMCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/SetAzureVMCommand.cs new file mode 100644 index 000000000000..a0fcd638a0e3 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/SetAzureVMCommand.cs @@ -0,0 +1,50 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Management.Compute; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Set, ProfileNouns.VirtualMachine, DefaultParameterSetName = ResourceGroupNameParameterSet)] + public class SetAzureVMCommand : VirtualMachineActionBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "To generalize virtual machine.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Generalized { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + this.VirtualMachineClient.Generalize(this.ResourceGroupName, this.Name); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/StartAzureVMCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/StartAzureVMCommand.cs new file mode 100644 index 000000000000..6569bf149244 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/StartAzureVMCommand.cs @@ -0,0 +1,45 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsLifecycle.Start, ProfileNouns.VirtualMachine, DefaultParameterSetName = ResourceGroupNameParameterSet)] + [OutputType(typeof(PSComputeLongRunningOperation))] + public class StartAzureVMCommand : VirtualMachineActionBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + this.VirtualMachineClient.Start(this.ResourceGroupName, this.Name); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/StopAzureVMCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/StopAzureVMCommand.cs new file mode 100644 index 000000000000..dff595e426c6 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/StopAzureVMCommand.cs @@ -0,0 +1,76 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using System; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsLifecycle.Stop, ProfileNouns.VirtualMachine, DefaultParameterSetName = ResourceGroupNameParameterSet)] + [OutputType(typeof(PSComputeLongRunningOperation))] + public class StopAzureVMCommand : VirtualMachineActionBaseCmdlet + { + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Mandatory = false, + HelpMessage = "To force the stopping.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Force { get; set; } + + [Parameter( + Mandatory = false, + HelpMessage = "To keep the VM provisioned.")] + [ValidateNotNullOrEmpty] + public SwitchParameter StayProvisioned { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + // TODO: Properties & Resourcess + //if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineStoppingConfirmation, Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineStoppingCaption)) + if (this.Force.IsPresent || this.ShouldContinue("Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineStoppingConfirmation", "Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineStoppingCaption")) + { + Action> call = f => + { + f(this.ResourceGroupName, this.Name); + }; + + if (this.StayProvisioned) + { + call(this.VirtualMachineClient.PowerOff); + } + else + { + call(this.VirtualMachineClient.Deallocate); + } + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/VirtualMachineActionBaseCmdlet.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/VirtualMachineActionBaseCmdlet.cs new file mode 100644 index 000000000000..0705d199f7c5 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/VirtualMachineActionBaseCmdlet.cs @@ -0,0 +1,61 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Management.Automation; +using System.Text.RegularExpressions; + +namespace Microsoft.Azure.Commands.Compute +{ + public abstract class VirtualMachineActionBaseCmdlet : VirtualMachineBaseCmdlet + { + protected const string ResourceGroupNameParameterSet = "ResourceGroupNameParameterSetName"; + protected const string IdParameterSet = "IdParameterSetName"; + + [Parameter( + Mandatory = true, + Position = 0, + ParameterSetName = ResourceGroupNameParameterSet, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + Position = 0, + ParameterSetName = IdParameterSet, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string Id { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + if (this.ParameterSetName.Equals(IdParameterSet)) + { + this.ResourceGroupName = GetResourceGroupNameFromId(this.Id); + } + } + + protected string GetResourceGroupNameFromId(string idString) + { + var match = Regex.Match(idString, @"resourceGroups/([A-Za-z0-9\-]+)/"); + return (match.Success) + ? match.Groups[1].Value + : null; + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMAdditionalUnattendContentCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMAdditionalUnattendContentCommand.cs new file mode 100644 index 000000000000..324aaaf14489 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMAdditionalUnattendContentCommand.cs @@ -0,0 +1,96 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using System; +using System.Collections.Generic; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + /// + /// Add an Additional Unattend Content Object to VM + /// + [Cmdlet( + VerbsCommon.Add, + ProfileNouns.AdditionalUnattendContent), + OutputType( + typeof(PSVirtualMachine))] + public class NewAzureAdditionalUnattendContentCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + private const string defaultComponentName = "Microsoft-Windows-Shell-Setup"; + private const string defaultPassName = "oobeSystem"; + + [Alias("VMProfile")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMProfile)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Parameter( + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "XML Formatted Content.")] + [ValidateNotNullOrEmpty] + public string Content { get; set; } + + [Parameter( + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Setting Name.")] + [ValidateNotNullOrEmpty] + public string SettingName { get; set; } + + protected override void ProcessRecord() + { + if (this.VM.OSProfile == null) + { + this.VM.OSProfile = new OSProfile(); + } + + if (this.VM.OSProfile.WindowsConfiguration == null && this.VM.OSProfile.LinuxConfiguration == null) + { + this.VM.OSProfile.WindowsConfiguration = new WindowsConfiguration(); + } + else if (this.VM.OSProfile.WindowsConfiguration == null && this.VM.OSProfile.LinuxConfiguration != null) + { + // TODO: Properties & Resources + throw new ArgumentException("Microsoft.Azure.Commands.Compute.Properties.Resources.BothWindowsAndLinuxConfigurationsSpecified"); + } + + if (this.VM.OSProfile.WindowsConfiguration.AdditionalUnattendContent == null) + { + this.VM.OSProfile.WindowsConfiguration.AdditionalUnattendContent = new List (); + } + + this.VM.OSProfile.WindowsConfiguration.AdditionalUnattendContent.Add( + new AdditionalUnattendContent + { + ComponentName = defaultComponentName, + Content = this.Content, + PassName = defaultPassName, + SettingName = this.SettingName, + }); + + WriteObject(this.VM); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMDataDiskCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMDataDiskCommand.cs new file mode 100644 index 000000000000..3c55744193f1 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMDataDiskCommand.cs @@ -0,0 +1,135 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using System.Collections.Generic; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Add, + ProfileNouns.DataDisk), + OutputType( + typeof(PSVirtualMachine))] + public class AddAzureVMDataDiskCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + [Alias("VMProfile")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMProfile)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskName)] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskVhdUri)] + [ValidateNotNullOrEmpty] + public string VhdUri { get; set; } + + [Parameter( + Mandatory = false, + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskCaching)] + [ValidateNotNullOrEmpty] + [ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite, ValidateSetValues.None)] + public string Caching { get; set; } + + [Parameter( + Mandatory = true, + Position = 4, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskSizeInGB)] + [AllowNull] + public int? DiskSizeInGB { get; set; } + + [Parameter( + Mandatory = false, + Position = 5, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskLun)] + [ValidateNotNullOrEmpty] + public int? Lun { get; set; } + + [Parameter( + Mandatory = true, + Position = 6, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskCreateOption)] + [ValidateNotNullOrEmpty] + [ValidateSet(DiskCreateOptionTypes.Empty, DiskCreateOptionTypes.Attach, DiskCreateOptionTypes.FromImage)] + public string CreateOption { get; set; } + + [Alias("SourceImage")] + [Parameter( + Position = 7, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMSourceImageUri)] + [ValidateNotNullOrEmpty] + public string SourceImageUri { get; set; } + + protected override void ProcessRecord() + { + var storageProfile = this.VM.StorageProfile; + + if (storageProfile == null) + { + storageProfile = new StorageProfile(); + } + + if (storageProfile.DataDisks == null) + { + storageProfile.DataDisks = new List(); + } + + storageProfile.DataDisks.Add(new DataDisk + { + Name = this.Name, + Caching = this.Caching, + DiskSizeGB = this.DiskSizeInGB, + Lun = this.Lun.GetValueOrDefault(), + Vhd = new VirtualHardDisk + { + Uri = this.VhdUri + }, + CreateOption = this.CreateOption, + Image = string.IsNullOrEmpty(this.SourceImageUri) ? null : new VirtualHardDisk + { + Uri = this.SourceImageUri + } + }); + + this.VM.StorageProfile = storageProfile; + + WriteObject(this.VM); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMNetworkInterfaceCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMNetworkInterfaceCommand.cs new file mode 100644 index 000000000000..2e1935b99abb --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMNetworkInterfaceCommand.cs @@ -0,0 +1,171 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute.Models; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + /// + /// Setup the network interface. + /// + [Cmdlet( + VerbsCommon.Add, + ProfileNouns.NetworkInterface, + DefaultParameterSetName = NicIdParamSetName), + OutputType( + typeof(PSVirtualMachine))] + public class AddAzureVMNetworkInterfaceCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + protected const string NicIdParamSetName = "GetNicFromNicId"; + protected const string NicObjectParamSetName = "GetNicFromNicObject"; + + [Alias("VMProfile")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + ParameterSetName = NicIdParamSetName, + HelpMessage = HelpMessages.VMProfile)] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + ParameterSetName = NicObjectParamSetName, + HelpMessage = HelpMessages.VMProfile)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Alias("NicId", "NetworkInterfaceId")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMNetworkInterfaceID, + ParameterSetName = NicIdParamSetName)] + [ValidateNotNullOrEmpty] + public string Id { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipeline = true, + ParameterSetName = NicObjectParamSetName)] + [ValidateNotNullOrEmpty] + public List NetworkInterface { get; set; } + + [Parameter( + Mandatory = false, + Position = 2, + ValueFromPipelineByPropertyName = true, + ParameterSetName = NicIdParamSetName)] + [ValidateNotNullOrEmpty] + public SwitchParameter Primary { get; set; } + + protected override void ProcessRecord() + { + var networkProfile = this.VM.NetworkProfile; + + if (networkProfile == null) + { + networkProfile = new NetworkProfile + { + NetworkInterfaces = new List() + }; + } + + if (networkProfile.NetworkInterfaces == null) + { + networkProfile.NetworkInterfaces = new List(); + } + + if (this.ParameterSetName.Equals(NicIdParamSetName)) + { + if (!this.Primary.IsPresent) + { + if (! networkProfile.NetworkInterfaces.Any(e => e.Id.Equals(this.Id))) + { + networkProfile.NetworkInterfaces.Add(new NetworkInterfaceReference + { + Id = this.Id, + }); + } + + if (networkProfile.NetworkInterfaces.Count > 1) + { + // run through the entire list of networkInterfaces and if Primary is not set, set them to false + foreach (var nic in networkProfile.NetworkInterfaces) + { + nic.Primary = nic.Primary ?? false; + } + } + } + else + { + foreach (var networkInterfaceReference in networkProfile.NetworkInterfaces) + { + networkInterfaceReference.Primary = false; + } + + var existingNic = networkProfile.NetworkInterfaces.Where(e => e.Id.Equals(this.Id)).FirstOrDefault(); + if (existingNic == null) + { + networkProfile.NetworkInterfaces.Add( + new NetworkInterfaceReference + { + Id = this.Id, + Primary = true + }); + } + else + { + existingNic.Primary = true; + } + } + } + else + { + // Nic Object Parameter Set + foreach (var nic in this.NetworkInterface) + { + var existingNic = networkProfile.NetworkInterfaces.Where(e => e.Id.Equals(nic.Id)).FirstOrDefault(); + + if (existingNic == null) + { + networkProfile.NetworkInterfaces.Add( + new NetworkInterfaceReference + { + Id = nic.Id, + Primary = nic.Primary + }); + } + else + { + existingNic.Primary = nic.Primary; + } + } + } + + this.VM.NetworkProfile = networkProfile; + + WriteObject(this.VM); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMSecretCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMSecretCommand.cs new file mode 100644 index 000000000000..02a155ff1ce4 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMSecretCommand.cs @@ -0,0 +1,128 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using System; +using System.Collections.Generic; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + /// + /// Add a Vault Secret Group object to VM + /// + [Cmdlet( + VerbsCommon.Add, + ProfileNouns.VaultSecretGroup), + OutputType( + typeof(PSVirtualMachine))] + public class NewAzureVaultSecretGroupCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + [Alias("VMProfile")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMProfile)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Alias("Id")] + [Parameter( + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The ID for Source Vault")] + [ValidateNotNullOrEmpty] + public string SourceVaultId { get; set; } + + [Parameter( + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Certificate store in LocalMachine")] + [ValidateNotNullOrEmpty] + public string CertificateStore { get; set; } + + [Parameter( + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = "URL referencing a secret in a Key Vault.")] + [ValidateNotNullOrEmpty] + public string CertificateUrl { get; set; } + + protected override void ProcessRecord() + { + if (this.VM.OSProfile == null) + { + this.VM.OSProfile = new OSProfile(); + } + + if (this.VM.OSProfile.Secrets == null) + { + this.VM.OSProfile.Secrets = new List(); + } + + int i = 0; + + for(; i <= this.VM.OSProfile.Secrets.Count; i++) + { + if (i == this.VM.OSProfile.Secrets.Count) + { + var sourceVault = new SubResource { + Id = this.SourceVaultId + }; + + var vaultCertificates = new List{ + new VaultCertificate() + { + CertificateStore = this.CertificateStore, + CertificateUrl = this.CertificateUrl, + } + }; + + this.VM.OSProfile.Secrets.Add( + new VaultSecretGroup() + { + SourceVault = sourceVault, + VaultCertificates = vaultCertificates, + }); + + break; + } + + if (this.VM.OSProfile.Secrets[i].SourceVault != null && this.VM.OSProfile.Secrets[i].SourceVault.Id.Equals(this.SourceVaultId)) + { + if (this.VM.OSProfile.Secrets[i].VaultCertificates == null) + { + this.VM.OSProfile.Secrets[i].VaultCertificates = new List(); + } + + this.VM.OSProfile.Secrets[i].VaultCertificates.Add( + new VaultCertificate() + { + CertificateStore = this.CertificateStore, + CertificateUrl = this.CertificateUrl, + }); + + break; + } + } + + WriteObject(this.VM); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMSshPublicKeyCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMSshPublicKeyCommand.cs new file mode 100644 index 000000000000..c03ca8bc4bce --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMSshPublicKeyCommand.cs @@ -0,0 +1,96 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Common.Properties; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute.Models; +using System; +using System.Collections.Generic; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + /// + /// Add an Ssh Public Key object to VM + /// + [Cmdlet( + VerbsCommon.Add, + ProfileNouns.SshPublicKey), + OutputType( + typeof(PSVirtualMachine))] + public class NewAzureSshPublicKeyCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + [Alias("VMProfile")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMProfile)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Parameter( + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Certificate Public Key")] + [ValidateNotNullOrEmpty] + public string KeyData { get; set; } + + [Parameter( + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Full Path on VM where SSH Public Key is Stored.")] + [ValidateNotNullOrEmpty] + public string Path { get; set; } + + protected override void ProcessRecord() + { + + if (this.VM.OSProfile == null) + { + this.VM.OSProfile = new OSProfile(); + } + + if (this.VM.OSProfile.WindowsConfiguration == null && this.VM.OSProfile.LinuxConfiguration == null) + { + this.VM.OSProfile.LinuxConfiguration = new LinuxConfiguration(); + } + else if (this.VM.OSProfile.WindowsConfiguration != null && this.VM.OSProfile.LinuxConfiguration == null) + { + throw new ArgumentException(Resources.ResourceManager.GetString("BothWindowsAndLinuxConfigurationsSpecified")); + } + + if (this.VM.OSProfile.LinuxConfiguration.Ssh == null) + { + this.VM.OSProfile.LinuxConfiguration.Ssh = new SshConfiguration(); + } + + if (this.VM.OSProfile.LinuxConfiguration.Ssh.PublicKeys == null) + { + this.VM.OSProfile.LinuxConfiguration.Ssh.PublicKeys = new List(); + } + + this.VM.OSProfile.LinuxConfiguration.Ssh.PublicKeys.Add( + new SshPublicKey + { + KeyData = this.KeyData, + Path = this.Path, + }); + + WriteObject(this.VM); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/NewAzureVMConfigCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/NewAzureVMConfigCommand.cs new file mode 100644 index 000000000000..95084eb45d2c --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/NewAzureVMConfigCommand.cs @@ -0,0 +1,79 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Management.Automation; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using Microsoft.Azure.Management.Compute.Models; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.New, + ProfileNouns.VirtualMachineConfig), + OutputType( + typeof(PSVirtualMachine))] + public class NewAzureVMConfigCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + [Alias("ResourceName", "Name")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The VM name.")] + [ValidateNotNullOrEmpty] + public string VMName { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMSize)] + [ValidateNotNullOrEmpty] + public string VMSize { get; set; } + + [Parameter( + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Availability Set Id.")] + [ValidateNotNullOrEmpty] + public string AvailabilitySetId { get; set; } + + protected override bool IsUsageMetricEnabled + { + get { return true; } + } + + protected override void ProcessRecord() + { + var vm = new PSVirtualMachine + { + Name = this.VMName, + AvailabilitySetReference = string.IsNullOrEmpty(this.AvailabilitySetId) ? null : new SubResource + { + Id = this.AvailabilitySetId + } + }; + + if (!string.IsNullOrEmpty(this.VMSize)) + { + vm.HardwareProfile = new HardwareProfile(); + vm.HardwareProfile.VmSize = this.VMSize; + } + + WriteObject(vm); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/RemoveAzureVMDataDiskCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/RemoveAzureVMDataDiskCommand.cs new file mode 100644 index 000000000000..e20be44a38f8 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/RemoveAzureVMDataDiskCommand.cs @@ -0,0 +1,70 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using System; +using System.Linq; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Remove, + ProfileNouns.DataDisk), + OutputType( + typeof(PSVirtualMachine))] + public class RemoveAzureVMDataDiskCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + [Alias("VMProfile")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMProfile)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Alias("Name")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskName)] + [ValidateNotNullOrEmpty] + public string[] DataDiskNames { get; set; } + + protected override void ProcessRecord() + { + var storageProfile = this.VM.StorageProfile; + + if (storageProfile != null && storageProfile.DataDisks != null) + { + var disks = storageProfile.DataDisks.ToList(); + var comp = StringComparison.OrdinalIgnoreCase; + foreach (var diskName in DataDiskNames) + { + disks.RemoveAll(d => string.Equals(d.Name, diskName, comp)); + } + storageProfile.DataDisks = disks; + } + + this.VM.StorageProfile = storageProfile; + + WriteObject(this.VM); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs new file mode 100644 index 000000000000..8393263449cd --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs @@ -0,0 +1,79 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Linq; +using System.Management.Automation; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; + +namespace Microsoft.Azure.Commands.Compute +{ + /// + /// Setup the network interface. + /// + [Cmdlet( + VerbsCommon.Remove, + ProfileNouns.NetworkInterface), + OutputType( + typeof(PSVirtualMachine))] + public class RemoveAzureVMNetworkInterfaceCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + [Alias("VMProfile")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMProfile)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Alias("Id", "NicIds")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMNetworkInterfaceID)] + [ValidateNotNullOrEmpty] + public string[] NetworkInterfaceIDs { get; set; } + + protected override void ProcessRecord() + { + var networkProfile = this.VM.NetworkProfile; + + foreach (var id in this.NetworkInterfaceIDs) + { + if (networkProfile != null && + networkProfile.NetworkInterfaces != null && + networkProfile.NetworkInterfaces.Any(nic => + string.Equals(nic.Id, id, StringComparison.OrdinalIgnoreCase))) + { + var nicReference = networkProfile.NetworkInterfaces.First(nic => string.Equals(nic.Id, id, StringComparison.OrdinalIgnoreCase)); + networkProfile.NetworkInterfaces.Remove(nicReference); + } + } + + if (!networkProfile.NetworkInterfaces.Any()) + { + networkProfile = null; + } + + this.VM.NetworkProfile = networkProfile; + + WriteObject(this.VM); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMBootDiagnosticsCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMBootDiagnosticsCommand.cs new file mode 100644 index 000000000000..9f22122562de --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMBootDiagnosticsCommand.cs @@ -0,0 +1,141 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Common.Authentication; +using Microsoft.Azure.Commands.Common.Authentication.Models; +using Microsoft.Azure.Commands.Common.Properties; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute.Models; +using Microsoft.Azure.Management.Storage; +using Microsoft.Azure.Management.Storage.Models; +using System; +using System.Globalization; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Set, + ProfileNouns.BootDiagnostics), + OutputType( + typeof(PSVirtualMachine))] + public class SetAzureVMBootDiagnosticsCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + private const string EnableParameterSet = "EnableBootDiagnostics"; + private const string DisableParameterSet = "DisableBootDiagnostics"; + + [Alias("VMProfile")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMProfile)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ParameterSetName = EnableParameterSet, + HelpMessage = HelpMessages.VMBootDiagnosticsEnable)] + public SwitchParameter Enable { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ParameterSetName = DisableParameterSet, + HelpMessage = HelpMessages.VMBootDiagnosticsDisable)] + public SwitchParameter Disable { get; set; } + + [Parameter( + Mandatory = true, + Position = 2, + ParameterSetName = EnableParameterSet, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMBootDiagnosticsResourceGroupName)] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = false, + Position = 3, + ParameterSetName = EnableParameterSet, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMBootDiagnosticsStorageAccountName)] + [ValidateNotNullOrEmpty] + public string StorageAccountName { get; set; } + + protected override void ProcessRecord() + { + var diagnosticsProfile = this.VM.DiagnosticsProfile; + + diagnosticsProfile = diagnosticsProfile ?? new DiagnosticsProfile(); + + diagnosticsProfile.BootDiagnostics = diagnosticsProfile.BootDiagnostics ?? new BootDiagnostics(); + + diagnosticsProfile.BootDiagnostics.Enabled = this.Enable.IsPresent; + + if (this.Enable.IsPresent) + { + if (string.IsNullOrEmpty(this.StorageAccountName)) + { + if (diagnosticsProfile.BootDiagnostics.StorageUri == null) + { + ThrowNoStorageAccount(); + } + } + else + { + var storageClient = ClientFactory.CreateClient( + DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager); + var storageAccount = storageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.StorageAccountName); + + if (storageAccount.AccountType.Equals(AccountType.PremiumLRS)) + { + ThrowPremiumStorageError(this.StorageAccountName); + } + + diagnosticsProfile.BootDiagnostics.StorageUri = storageAccount.PrimaryEndpoints.Blob; + } + } + + this.VM.DiagnosticsProfile = diagnosticsProfile; + + WriteObject(this.VM); + } + + private void ThrowPremiumStorageError(string storageAccountName) + { + ThrowTerminatingError + (new ErrorRecord( + new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, + Resources.ResourceManager.GetString("PremiumStorageAccountForBootDiagnostics"), storageAccountName)), + string.Empty, + ErrorCategory.InvalidData, + null)); + } + + private void ThrowNoStorageAccount() + { + ThrowTerminatingError + (new ErrorRecord( + new InvalidOperationException(Resources.ResourceManager.GetString("BootDiagnosticsNoStorageAccountError")), + string.Empty, + ErrorCategory.InvalidData, + null)); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMDataDiskCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMDataDiskCommand.cs new file mode 100644 index 000000000000..2a1ad1fe0a06 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMDataDiskCommand.cs @@ -0,0 +1,132 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Commands.Compute.Properties; +using Microsoft.Azure.Management.Compute.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Set, + ProfileNouns.DataDisk), + OutputType( + typeof(PSVirtualMachine))] + public class SetAzureVMDataDiskCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + private const string NameParameterSet = "ChangeWithName"; + private const string LunParameterSet = "ChangeWithLun"; + + [Alias("VMProfile")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMProfile)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ParameterSetName = NameParameterSet, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskName)] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ParameterSetName = LunParameterSet, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskLun)] + [ValidateNotNullOrEmpty] + public int? Lun { get; set; } + + [Parameter( + Mandatory = false, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskCaching)] + [ValidateNotNullOrEmpty] + [ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite, ValidateSetValues.None)] + public string Caching { get; set; } + + [Parameter( + Mandatory = false, + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskSizeInGB)] + [AllowNull] + public int? DiskSizeInGB { get; set; } + + protected override void ProcessRecord() + { + var storageProfile = this.VM.StorageProfile; + + if (storageProfile == null || storageProfile.DataDisks == null) + { + ThrowDataDiskNotExistError(); + } + + var dataDisk = (this.ParameterSetName.Equals(LunParameterSet)) + ? storageProfile.DataDisks.SingleOrDefault(disk => disk.Lun == this.Lun) + : storageProfile.DataDisks.SingleOrDefault(disk => disk.Name == this.Name); + + if (dataDisk == null) + { + ThrowDataDiskNotExistError(); + } + else + { + if (! string.IsNullOrWhiteSpace(this.Caching)) + { + dataDisk.Caching = this.Caching; + } + if (this.DiskSizeInGB != null) + { + dataDisk.DiskSizeGB = this.DiskSizeInGB; + } + } + + this.VM.StorageProfile = storageProfile; + + WriteObject(this.VM); + } + + private void ThrowDataDiskNotExistError() + { + var missingDisk = (this.ParameterSetName.Equals(LunParameterSet)) + ? string.Format("LUN # {0}", this.Lun) + : "Name: " + this.Name; + + ThrowTerminatingError + (new ErrorRecord( + new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, + Resources.ResourceManager.GetString("DataDiskNotAssignedForVM"), missingDisk)), + string.Empty, + ErrorCategory.InvalidData, + null)); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMOSDiskCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMOSDiskCommand.cs new file mode 100644 index 000000000000..446a6afcee5e --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMOSDiskCommand.cs @@ -0,0 +1,229 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Management.Automation; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using Microsoft.Azure.Management.Compute.Models; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet( + VerbsCommon.Set, + ProfileNouns.OSDisk, + DefaultParameterSetName = DefaultParamSet), + OutputType( + typeof(PSVirtualMachine))] + public class SetAzureVMOSDiskCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + protected const string DefaultParamSet = "DefaultParamSet"; + protected const string WindowsParamSet = "WindowsParamSet"; + protected const string LinuxParamSet = "LinuxParamSet"; + protected const string WindowsAndDiskEncryptionParameterSet = "WindowsDiskEncryptionParameterSet"; + protected const string LinuxAndDiskEncryptionParameterSet = "LinuxDiskEncryptionParameterSet"; + + [Alias("VMProfile")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMProfile)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Alias("OSDiskName", "DiskName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskName)] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Alias("OSDiskVhdUri", "DiskVhdUri")] + [Parameter( + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskVhdUri)] + [ValidateNotNullOrEmpty] + public string VhdUri { get; set; } + + [Parameter( + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskCaching)] + [ValidateNotNullOrEmpty] + [ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite, ValidateSetValues.None)] + public string Caching { get; set; } + + [Alias("SourceImage")] + [Parameter( + Position = 4, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMSourceImageUri)] + [ValidateNotNullOrEmpty] + public string SourceImageUri { get; set; } + + [Parameter( + Mandatory = true, + Position = 5, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMDataDiskCreateOption)] + [ValidateNotNullOrEmpty] + [ValidateSet(DiskCreateOptionTypes.Empty, DiskCreateOptionTypes.Attach, DiskCreateOptionTypes.FromImage)] + public string CreateOption { get; set; } + + [Parameter( + ParameterSetName = WindowsParamSet, + Position = 6, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskWindowsOSType)] + [Parameter( + ParameterSetName = WindowsAndDiskEncryptionParameterSet, + Position = 6, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskWindowsOSType)] + public SwitchParameter Windows { get; set; } + + [Parameter( + ParameterSetName = LinuxParamSet, + Position = 6, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskLinuxOSType)] + [Parameter( + ParameterSetName = LinuxAndDiskEncryptionParameterSet, + Position = 6, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskLinuxOSType)] + public SwitchParameter Linux { get; set; } + + [Parameter( + ParameterSetName = WindowsAndDiskEncryptionParameterSet, + Mandatory = true, + Position = 7, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskDiskEncryptionKeyUrl)] + [Parameter( + ParameterSetName = LinuxAndDiskEncryptionParameterSet, + Mandatory = true, + Position = 7, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskDiskEncryptionKeyUrl)] + public string DiskEncryptionKeyUrl { get; set; } + + [Parameter( + ParameterSetName = WindowsAndDiskEncryptionParameterSet, + Mandatory = true, + Position = 8, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskDiskEncryptionKeyVaultId)] + [Parameter( + ParameterSetName = LinuxAndDiskEncryptionParameterSet, + Mandatory = true, + Position = 8, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskDiskEncryptionKeyVaultId)] + public string DiskEncryptionKeyVaultId { get; set; } + + [Parameter( + ParameterSetName = WindowsAndDiskEncryptionParameterSet, + Mandatory = false, + Position = 9, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskKeyEncryptionKeyUrl)] + [Parameter( + ParameterSetName = LinuxAndDiskEncryptionParameterSet, + Mandatory = false, + Position = 9, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskKeyEncryptionKeyUrl)] + public string KeyEncryptionKeyUrl { get; set; } + + [Parameter( + ParameterSetName = WindowsAndDiskEncryptionParameterSet, + Mandatory = false, + Position = 10, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskKeyEncryptionKeyVaultId)] + [Parameter( + ParameterSetName = LinuxAndDiskEncryptionParameterSet, + Mandatory = false, + Position = 10, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMOSDiskKeyEncryptionKeyVaultId)] + public string KeyEncryptionKeyVaultId { get; set; } + + protected override void ProcessRecord() + { + if (this.VM.StorageProfile == null) + { + this.VM.StorageProfile = new StorageProfile(); + } + + if ((string.IsNullOrEmpty(this.KeyEncryptionKeyVaultId) && !string.IsNullOrEmpty(this.KeyEncryptionKeyUrl)) + || (!string.IsNullOrEmpty(this.KeyEncryptionKeyVaultId) && string.IsNullOrEmpty(this.KeyEncryptionKeyUrl))) + { + WriteError(new ErrorRecord( + new Exception(Properties.Resources.ResourceManager.GetString("VMOSDiskDiskEncryptionBothKekVaultIdAndKekUrlRequired")), + string.Empty, ErrorCategory.InvalidArgument, null)); + } + + this.VM.StorageProfile.OsDisk = new OSDisk + { + Caching = this.Caching, + Name = this.Name, + OsType = this.Windows.IsPresent ? OperatingSystemTypes.Windows : this.Linux.IsPresent ? OperatingSystemTypes.Linux : null, + Vhd = string.IsNullOrEmpty(this.VhdUri) ? null : new VirtualHardDisk + { + Uri = this.VhdUri + }, + Image = string.IsNullOrEmpty(this.SourceImageUri) ? null : new VirtualHardDisk + { + Uri = this.SourceImageUri + }, + CreateOption = this.CreateOption, + EncryptionSettings = + (this.ParameterSetName.Equals(WindowsAndDiskEncryptionParameterSet) || this.ParameterSetName.Equals(LinuxAndDiskEncryptionParameterSet)) + ? new DiskEncryptionSettings + { + DiskEncryptionKey = new KeyVaultSecretReference + { + SourceVault = new SubResource + { + Id = this.DiskEncryptionKeyVaultId + }, + SecretUrl = this.DiskEncryptionKeyUrl + }, + KeyEncryptionKey = (this.KeyEncryptionKeyVaultId == null || this.KeyEncryptionKeyUrl == null) + ? null + : new KeyVaultKeyReference + { + KeyUrl = this.KeyEncryptionKeyUrl, + SourceVault = new SubResource + { + Id = this.KeyEncryptionKeyVaultId + }, + } + } + : null + }; + + WriteObject(this.VM); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMOperatingSystemCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMOperatingSystemCommand.cs new file mode 100644 index 000000000000..ca21f8ec964e --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMOperatingSystemCommand.cs @@ -0,0 +1,237 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Commands.Compute.Properties; +using Microsoft.Azure.Management.Compute.Models; +using Microsoft.WindowsAzure.Commands.Common; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using System; +using System.Collections.Generic; +using System.Management.Automation; +using System.Text; + +namespace Microsoft.Azure.Commands.Compute +{ + /// + /// Setup the virtual machine's OS profile. + /// + [Cmdlet( + VerbsCommon.Set, + ProfileNouns.OperatingSystem, + DefaultParameterSetName = WindowsParamSet), + OutputType( + typeof(PSVirtualMachine))] + public class SetAzureVMOperatingSystemCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + protected const string WindowsParamSet = "Windows"; + protected const string LinuxParamSet = "Linux"; + + [Alias("VMProfile")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMProfile)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Parameter( + ParameterSetName = WindowsParamSet, + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Windows")] + [ValidateNotNullOrEmpty] + public SwitchParameter Windows { get; set; } + + [Parameter( + ParameterSetName = LinuxParamSet, + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Linux")] + [ValidateNotNullOrEmpty] + public SwitchParameter Linux { get; set; } + + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMComputerName)] + [ValidateNotNullOrEmpty] + public string ComputerName { get; set; } + + [Parameter( + Mandatory = true, + Position = 3, + ValueFromPipelineByPropertyName = true, + HelpMessage = HelpMessages.VMCredential)] + [ValidateNotNullOrEmpty] + public PSCredential Credential { get; set; } + + [Parameter( + Position = 4, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Custom data")] + [ValidateNotNullOrEmpty] + public string CustomData { get; set; } + + [Parameter( + ParameterSetName = WindowsParamSet, + Position = 5, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The Provision VM Agent.")] + [ValidateNotNullOrEmpty] + public SwitchParameter ProvisionVMAgent { get; set; } + + [Parameter( + ParameterSetName = WindowsParamSet, + Position = 6, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Enable Automatic Update")] + [ValidateNotNullOrEmpty] + public SwitchParameter EnableAutoUpdate { get; set; } + + [Parameter( + ParameterSetName = WindowsParamSet, + Position = 7, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Time Zone")] + [ValidateNotNullOrEmpty] + public string TimeZone { get; set; } + + [Parameter( + ParameterSetName = WindowsParamSet, + Position = 8, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Enable WinRM Http protocol")] + [ValidateNotNullOrEmpty] + public SwitchParameter WinRMHttp { get; set; } + + [Parameter( + ParameterSetName = WindowsParamSet, + Position = 9, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Enable WinRM Https protocol")] + [ValidateNotNullOrEmpty] + public SwitchParameter WinRMHttps { get; set; } + + [Parameter( + ParameterSetName = WindowsParamSet, + Position = 10, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Url for WinRM certificate")] + [ValidateNotNullOrEmpty] + public Uri WinRMCertificateUrl { get; set; } + + // Linux Parameter Sets + [Parameter( + ParameterSetName = LinuxParamSet, + Position = 5, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Enable WinRM Https protocol")] + [ValidateNotNullOrEmpty] + public SwitchParameter DisablePasswordAuthentication { get; set; } + + protected override void ProcessRecord() + { + this.VM.OSProfile = new OSProfile + { + ComputerName = this.ComputerName, + AdminUsername = this.Credential.UserName, + // TODO: SecureString + //AdminPassword = SecureStringExtensions.ConvertToString(this.Credential.Password), + AdminPassword = this.Credential.Password, + CustomData = string.IsNullOrWhiteSpace(this.CustomData) ? null : Convert.ToBase64String(Encoding.UTF8.GetBytes(this.CustomData)), + }; + + if (this.ParameterSetName == LinuxParamSet) + { + if (this.VM.OSProfile.WindowsConfiguration != null) + { + throw new ArgumentException(Resources.ResourceManager.GetString("BothWindowsAndLinuxConfigurationsSpecified")); + } + + if (this.VM.OSProfile.LinuxConfiguration == null) + { + this.VM.OSProfile.LinuxConfiguration = new LinuxConfiguration(); + } + + this.VM.OSProfile.LinuxConfiguration.DisablePasswordAuthentication = + (this.DisablePasswordAuthentication.IsPresent) + ? (bool?)true + : null; + } + else + { + if (this.VM.OSProfile.LinuxConfiguration != null) + { + throw new ArgumentException(Resources.ResourceManager.GetString("BothWindowsAndLinuxConfigurationsSpecified")); + } + + if (this.VM.OSProfile.WindowsConfiguration == null) + { + this.VM.OSProfile.WindowsConfiguration = new WindowsConfiguration(); + this.VM.OSProfile.WindowsConfiguration.AdditionalUnattendContent = null; + } + + var listenerList = new List(); + + if (this.WinRMHttp.IsPresent) + { + listenerList.Add(new WinRMListener + { + Protocol = ProtocolTypes.Http, + CertificateUrl = null, + }); + } + + if (this.WinRMHttps.IsPresent) + { + listenerList.Add(new WinRMListener + { + Protocol = ProtocolTypes.Https, + CertificateUrl = this.WinRMCertificateUrl.ToString(), + }); + } + + // OS Profile + this.VM.OSProfile.WindowsConfiguration.ProvisionVMAgent = + (this.ProvisionVMAgent.IsPresent) + ? (bool?) true + : null; + + this.VM.OSProfile.WindowsConfiguration.EnableAutomaticUpdates = + this.EnableAutoUpdate.IsPresent + ? (bool?) true + : null; + + this.VM.OSProfile.WindowsConfiguration.TimeZone = this.TimeZone; + + this.VM.OSProfile.WindowsConfiguration.WinRM = + ! (this.WinRMHttp.IsPresent || this.WinRMHttps.IsPresent) + ? null + : new WinRMConfiguration + { + Listeners = listenerList, + }; + } + + WriteObject(this.VM); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMSourceImage.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMSourceImage.cs new file mode 100644 index 000000000000..48fc642d9a73 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMSourceImage.cs @@ -0,0 +1,70 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Management.Automation; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using Microsoft.Azure.Management.Compute.Models; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Set, ProfileNouns.SourceImage, DefaultParameterSetName = ImageReferenceParameterSet), + OutputType(typeof(PSVirtualMachine))] + public class SetAzureVMSourceImageCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + protected const string ImageReferenceParameterSet = "ImageReferenceParameterSet"; + + [Alias("VMProfile")] + [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Parameter(ParameterSetName = ImageReferenceParameterSet, Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string PublisherName { get; set; } + + [Parameter(ParameterSetName = ImageReferenceParameterSet, Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string Offer { get; set; } + + [Parameter(ParameterSetName = ImageReferenceParameterSet, Mandatory = true, Position = 3, ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string Skus { get; set; } + + [Parameter(ParameterSetName = ImageReferenceParameterSet, Mandatory = true, Position = 4, ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string Version { get; set; } + + protected override void ProcessRecord() + { + if (this.VM.StorageProfile == null) + { + this.VM.StorageProfile = new StorageProfile(); + } + + this.VM.StorageProfile.ImageReference = new ImageReference + { + Publisher = PublisherName, + Offer = Offer, + Sku = Skus, + Version = Version + }; + + WriteObject(this.VM); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/GetAzureVMBootDiagnosticsDataCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/GetAzureVMBootDiagnosticsDataCommand.cs new file mode 100644 index 000000000000..6c674f6b365e --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/GetAzureVMBootDiagnosticsDataCommand.cs @@ -0,0 +1,183 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Common.Authentication.Models; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Storage; +using Microsoft.WindowsAzure.Storage.Auth; +using Microsoft.WindowsAzure.Storage.Blob; +using System; +using System.Globalization; +using System.IO; +using System.Management.Automation; +using System.Text; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, ProfileNouns.BootDiagnosticsData, DefaultParameterSetName = WindowsParamSet)] + [OutputType(typeof(PSVirtualMachine), typeof(PSVirtualMachineInstanceView))] + public class GetAzureVMBootDiagnosticsDataCommand : VirtualMachineBaseCmdlet + { + private const string WindowsParamSet = "WindowsParamSet"; + private const string LinuxParamSet = "LinuxParamSet"; + + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName", "VMName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Mandatory = true, + Position = 2, + ParameterSetName = WindowsParamSet)] + public SwitchParameter Windows { get; set; } + + [Parameter( + Mandatory = true, + Position = 2, + ParameterSetName = LinuxParamSet)] + public SwitchParameter Linux { get; set; } + + [Parameter( + Mandatory = true, + Position = 3, + ParameterSetName = WindowsParamSet, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Path and name of the output RDP file.")] + [Parameter( + Mandatory = false, + Position = 3, + ParameterSetName = LinuxParamSet, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Path and name of the output RDP file.")] + [ValidateNotNullOrEmpty] + public string LocalPath { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + var result = this.VirtualMachineClient.Get(this.ResourceGroupName, this.Name, "instanceView"); + if (result == null) + { + ThrowTerminatingError + (new ErrorRecord( + new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, + "no virtual machine")), + string.Empty, + ErrorCategory.InvalidData, + null)); + } + + if (result.DiagnosticsProfile == null + || result.DiagnosticsProfile.BootDiagnostics == null + || result.DiagnosticsProfile.BootDiagnostics.Enabled == null + || !result.DiagnosticsProfile.BootDiagnostics.Enabled.Value + || result.DiagnosticsProfile.BootDiagnostics.StorageUri == null) + { + ThrowTerminatingError + (new ErrorRecord( + new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, + "no diagnostic profile enabled")), + string.Empty, + ErrorCategory.InvalidData, + null)); + } + + if (result.InstanceView == null + || result.InstanceView.BootDiagnostics == null) + { + ThrowTerminatingError + (new ErrorRecord( + new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, + "no boot diagnostic")), + string.Empty, + ErrorCategory.InvalidData, + null)); + } + + if (this.Windows.IsPresent + || (this.Linux.IsPresent && !string.IsNullOrEmpty(this.LocalPath))) + { + var screenshotUri = new Uri(result.InstanceView.BootDiagnostics.ConsoleScreenshotBlobUri); + var localFile = this.LocalPath + screenshotUri.Segments[2]; + DownloadFromBlobUri(screenshotUri, localFile); + } + + + if (this.Linux.IsPresent) + { + var logUri = new Uri(result.InstanceView.BootDiagnostics.SerialConsoleLogBlobUri); + + var localFile = (this.LocalPath ?? Path.GetTempPath()) + logUri.Segments[2]; + + DownloadFromBlobUri(logUri, localFile); + + var sb = new StringBuilder(); + using (var reader = new StreamReader(System.IO.File.OpenRead(localFile))) + { + string line; + while ((line = reader.ReadLine()) != null) + { + sb.AppendLine(line); + } + }; + + WriteObject(sb.ToString()); + } + }); + } + + private void DownloadFromBlobUri(Uri sourceUri, string localFileInfo) + { + // TODO : BlobUri + //BlobUri blobUri; + //string storagekey=""; + //if (!BlobUri.TryParseUri(sourceUri, out blobUri)) + //{ + // throw new ArgumentOutOfRangeException("Source", sourceUri.ToString()); + //} + // + //var storageClient = ClientFactory.CreateClient( + // DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager); + // + // + //var storageService = storageClient.StorageAccounts.GetProperties(this.ResourceGroupName, blobUri.StorageAccountName); + //if (storageService != null) + //{ + // var storageKeys = storageClient.StorageAccounts.ListKeys(this.ResourceGroupName, storageService.Name); + // storagekey = storageKeys.Key1; + //} + + //StorageCredentials storagecred = new StorageCredentials(blobUri.StorageAccountName, storagekey); + //var blob = new CloudBlob(sourceUri, storagecred); + // + //blob.DownloadToFile(localFileInfo, FileMode.Create); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/GetAzureVMCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/GetAzureVMCommand.cs new file mode 100644 index 000000000000..36b4c5bd173e --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/GetAzureVMCommand.cs @@ -0,0 +1,136 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using Microsoft.Rest.Azure; +using System; +using System.Collections.Generic; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachine, DefaultParameterSetName = ListAllVirtualMachinesParamSet)] + [OutputType(typeof(PSVirtualMachine), typeof(PSVirtualMachineInstanceView))] + public class GetAzureVMCommand : VirtualMachineBaseCmdlet + { + protected const string GetVirtualMachineInResourceGroupParamSet = "GetVirtualMachineInResourceGroupParamSet"; + protected const string ListVirtualMachineInResourceGroupParamSet = "ListVirtualMachineInResourceGroupParamSet"; + protected const string ListAllVirtualMachinesParamSet = "ListAllVirtualMachinesParamSet"; + protected const string ListNextLinkVirtualMachinesParamSet = "ListNextLinkVirtualMachinesParamSet"; + + [Parameter( + Mandatory = true, + Position = 0, + ParameterSetName = ListVirtualMachineInResourceGroupParamSet, + ValueFromPipelineByPropertyName = true)] + [Parameter( + Mandatory = true, + Position = 0, + ParameterSetName = GetVirtualMachineInResourceGroupParamSet, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Alias("ResourceName", "VMName")] + [Parameter( + Mandatory = true, + Position = 1, + ParameterSetName = GetVirtualMachineInResourceGroupParamSet, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Position = 2, + ParameterSetName = GetVirtualMachineInResourceGroupParamSet)] + [ValidateNotNullOrEmpty] + public SwitchParameter Status { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ParameterSetName = ListNextLinkVirtualMachinesParamSet, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public Uri NextLink { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + if (!string.IsNullOrEmpty(this.Name)) + { + if (Status) + { + var result = this.VirtualMachineClient.Get(this.ResourceGroupName, this.Name, "instanceView"); + WriteObject(result.ToPSVirtualMachineInstanceView(this.ResourceGroupName, this.Name)); + } + else + { + var result = this.VirtualMachineClient.Get(this.ResourceGroupName, this.Name); + var psResult = Mapper.Map(result); + WriteObject(psResult); + } + } + else + { + IPage vmListResult = null; + if (!string.IsNullOrEmpty(this.ResourceGroupName)) + { + vmListResult = this.VirtualMachineClient.List(this.ResourceGroupName); + } + else if (this.NextLink != null) + { + vmListResult = this.VirtualMachineClient.ListNext(this.NextLink.ToString()); + } + else + { + vmListResult = this.VirtualMachineClient.ListAll(); + } + + var psResultList = new List(); + + while (vmListResult != null) + { + if (vmListResult != null) + { + foreach (var item in vmListResult) + { + var psItem = Mapper.Map(item); + psResultList.Add(psItem); + } + } + + if (!string.IsNullOrEmpty(vmListResult.NextPageLink)) + { + vmListResult = this.VirtualMachineClient.ListNext(vmListResult.NextPageLink); + } + else + { + vmListResult = null; + } + } + + WriteObject(psResultList, true); + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs new file mode 100644 index 000000000000..10a813b329ca --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs @@ -0,0 +1,244 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Common.Authentication.Models; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Commands.Compute.Properties; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using Microsoft.Azure.Management.Storage; +using Microsoft.Azure.Management.Storage.Models; +using System; +using System.Collections; +using System.Linq; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.New, ProfileNouns.VirtualMachine)] + [OutputType(typeof(PSComputeLongRunningOperation))] + public class NewAzureVMCommand : VirtualMachineBaseCmdlet + { + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + + [Alias("VMProfile")] + [Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Parameter(ValueFromPipelineByPropertyName = true)] + public Hashtable[] Tags { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + if (this.VM.DiagnosticsProfile == null) + { + var storageUri = GetOrCreateStorageAccountForBootDiagnostics(); + + if (storageUri != null) + { + this.VM.DiagnosticsProfile = new DiagnosticsProfile + { + BootDiagnostics = new BootDiagnostics + { + Enabled = true, + StorageUri = storageUri.ToString(), + } + }; + } + } + + ExecuteClientAction(() => + { + var parameters = new VirtualMachine + { + DiagnosticsProfile = this.VM.DiagnosticsProfile, + HardwareProfile = this.VM.HardwareProfile, + StorageProfile = this.VM.StorageProfile, + NetworkProfile = this.VM.NetworkProfile, + OsProfile = this.VM.OSProfile, + Plan = this.VM.Plan, + AvailabilitySet = this.VM.AvailabilitySetReference, + Location = !string.IsNullOrEmpty(this.Location) ? this.Location : this.VM.Location, + Tags = this.Tags != null ? this.Tags.ToDictionary() : this.VM.Tags + }; + + var op = this.VirtualMachineClient.CreateOrUpdate(this.ResourceGroupName, this.VM.Name, parameters); + var result = Mapper.Map(op); + WriteObject(result); + }); + } + + private Uri GetOrCreateStorageAccountForBootDiagnostics() + { + var storageAccountName = GetStorageAccountNameFromStorageProfile(); + var storageClient = + ClientFactory.CreateClient(DefaultProfile.Context, + AzureEnvironment.Endpoint.ResourceManager); + + if (!string.IsNullOrEmpty(storageAccountName)) + { + try + { + var storageAccountResponse = storageClient.StorageAccounts.GetProperties(this.ResourceGroupName, + storageAccountName); + if (!storageAccountResponse.AccountType.Equals(AccountType.PremiumLRS)) + { + return new Uri(storageAccountResponse.PrimaryEndpoints.Blob); + } + } + catch (Exception e) + { + if (e.Message.Contains("ResourceNotFound")) + { + WriteWarning(string.Format( + Properties.Resources.ResourceManager.GetString("StorageAccountNotFoundForBootDiagnostics"), storageAccountName)); + } + else + { + WriteWarning(string.Format( + Properties.Resources.ResourceManager.GetString("ErrorDuringGettingStorageAccountForBootDiagnostics"), storageAccountName, e.Message)); + } + } + } + + var storageAccount = TryToChooseExistingStandardStorageAccount(storageClient); + + if (storageAccount == null) + { + return CreateStandardStorageAccount(storageClient); + } + + WriteWarning(string.Format(Properties.Resources.ResourceManager.GetString("UsingExistingStorageAccountForBootDiagnostics"), storageAccount.Name)); + + return new Uri(storageAccount.PrimaryEndpoints.Blob); + } + + private string GetStorageAccountNameFromStorageProfile() + { + if (this.VM == null + || this.VM.StorageProfile == null + || this.VM.StorageProfile.OsDisk == null + || this.VM.StorageProfile.OsDisk.Vhd == null + || this.VM.StorageProfile.OsDisk.Vhd.Uri == null) + { + return null; + } + + return GetStorageAccountNameFromUriString(this.VM.StorageProfile.OsDisk.Vhd.Uri); + } + + private StorageAccount TryToChooseExistingStandardStorageAccount(StorageManagementClient client) + { + var storageAccountList = client.StorageAccounts.ListByResourceGroup(this.ResourceGroupName); + if (storageAccountList == null) + { + return null; + } + + try + { + return storageAccountList.First( + e => e.AccountType.HasValue && !e.AccountType.Value.Equals(AccountType.PremiumLRS)); + } + catch (InvalidOperationException e) + { + if (e.Message.Contains("Sequence contains no matching element")) + { + return null; + } + throw; + } + } + + private Uri CreateStandardStorageAccount(StorageManagementClient client) + { + string storageAccountName; + + var i = 0; + bool? nameAvailable = null; + do + { + storageAccountName = GetRandomStorageAccountName(i); + i++; + + nameAvailable = client.StorageAccounts.CheckNameAvailability(storageAccountName).NameAvailable; + } + while (i < 10 && nameAvailable.HasValue && nameAvailable.Value); + + var storaeAccountParameter = new StorageAccountCreateParameters + { + AccountType = AccountType.StandardGRS, + Location = this.Location ?? this.VM.Location, + }; + + try + { + client.StorageAccounts.Create(this.ResourceGroupName, storageAccountName, storaeAccountParameter); + var getresponse = client.StorageAccounts.GetProperties(this.ResourceGroupName, storageAccountName); + WriteWarning(string.Format(Resources.ResourceManager.GetString("CreatingStorageAccountForBootDiagnostics"), storageAccountName)); + + return new Uri(getresponse.PrimaryEndpoints.Blob); + } + catch (Exception e) + { + // Failed to create a storage account for boot diagnostics. + WriteWarning(string.Format(Properties.Resources.ResourceManager.GetString("ErrorDuringCreatingStorageAccountForBootDiagnostics"), e)); + return null; + } + } + + private string GetRandomStorageAccountName(int interation) + { + const int maxSubLength = 5; + const int maxResLength = 6; + const int maxVMLength = 4; + + var subscriptionName = VirtualMachineCmdletHelper.GetTruncatedStr(this.DefaultContext.Subscription.Name, maxSubLength); + var resourcename = VirtualMachineCmdletHelper.GetTruncatedStr(this.ResourceGroupName, maxResLength); + var vmname = VirtualMachineCmdletHelper.GetTruncatedStr(this.VM.Name, maxVMLength); + var datetimestr = DateTime.Now.ToString("MMddHHmm"); + + var output = subscriptionName + resourcename + vmname + datetimestr + interation; + + output = new string((from c in output where char.IsLetterOrDigit(c) select c).ToArray()); + + return output.ToLowerInvariant(); + } + + private static string GetStorageAccountNameFromUriString(string uriStr) + { + Uri uri; + + if (!Uri.TryCreate(uriStr, UriKind.RelativeOrAbsolute, out uri)) + { + return null; + } + + var storageUri = uri.Authority; + var index = storageUri.IndexOf('.'); + return storageUri.Substring(0, index); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/RemoveAzureVMCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/RemoveAzureVMCommand.cs new file mode 100644 index 000000000000..b9e66d33327a --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/RemoveAzureVMCommand.cs @@ -0,0 +1,55 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Commands.Compute.Properties; +using Microsoft.Azure.Management.Compute; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Remove, ProfileNouns.VirtualMachine, DefaultParameterSetName = ResourceGroupNameParameterSet)] + [OutputType(typeof(PSComputeLongRunningOperation))] + public class RemoveAzureVMCommand : VirtualMachineActionBaseCmdlet + { + [Alias("ResourceName", "VMName")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Position = 2, + HelpMessage = "To force the removal.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Force { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + ExecuteClientAction(() => + { + if (this.Force.IsPresent || this.ShouldContinue(Resources.ResourceManager.GetString("VirtualMachineRemovalConfirmation"), Resources.ResourceManager.GetString("VirtualMachineRemovalCaption"))) + { + this.VirtualMachineClient.Delete(this.ResourceGroupName, this.Name); + } + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/UpdateAzureVMCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/UpdateAzureVMCommand.cs new file mode 100644 index 000000000000..6a48dcf8db56 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Operation/UpdateAzureVMCommand.cs @@ -0,0 +1,62 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using AutoMapper; +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using System.Collections; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsData.Update, ProfileNouns.VirtualMachine, DefaultParameterSetName = ResourceGroupNameParameterSet)] + [OutputType(typeof(PSComputeLongRunningOperation))] + public class UpdateAzureVMCommand : VirtualMachineActionBaseCmdlet + { + [Alias("VMProfile")] + [Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public PSVirtualMachine VM { get; set; } + + [Parameter(ValueFromPipelineByPropertyName = true)] + public Hashtable[] Tags { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + var parameters = new VirtualMachine + { + DiagnosticsProfile = this.VM.DiagnosticsProfile, + HardwareProfile = this.VM.HardwareProfile, + StorageProfile = this.VM.StorageProfile, + NetworkProfile = this.VM.NetworkProfile, + OsProfile = this.VM.OSProfile, + Plan = this.VM.Plan, + AvailabilitySet = this.VM.AvailabilitySetReference, + Location = this.VM.Location, + Tags = this.Tags != null ? this.Tags.ToDictionary() : this.VM.Tags + }; + + var op = this.VirtualMachineClient.CreateOrUpdate(this.ResourceGroupName, this.VM.Name, parameters); + var result = Mapper.Map(op); + WriteObject(result); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/VirtualMachineBaseCmdlet.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/VirtualMachineBaseCmdlet.cs new file mode 100644 index 000000000000..1528ccb647fa --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/VirtualMachineBaseCmdlet.cs @@ -0,0 +1,29 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.Compute; + +namespace Microsoft.Azure.Commands.Compute +{ + public abstract class VirtualMachineBaseCmdlet : ComputeClientBaseCmdlet + { + public IVirtualMachinesOperations VirtualMachineClient + { + get + { + return ComputeClient.ComputeManagementClient.VirtualMachines; + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/VirtualMachineCmdletHelper.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/VirtualMachineCmdletHelper.cs new file mode 100644 index 000000000000..b183ac9d1c9e --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/VirtualMachineCmdletHelper.cs @@ -0,0 +1,27 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Compute +{ + public class VirtualMachineCmdletHelper + { + public static string GetTruncatedStr(string inputStr, int maxLength) + { + if (inputStr == null) return string.Empty; + return (inputStr.Length > maxLength) + ? inputStr.Substring(0, maxLength) + : inputStr; + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachineSizes/GetAzureVMSizeCommand.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachineSizes/GetAzureVMSizeCommand.cs new file mode 100644 index 000000000000..7e0fc306e992 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachineSizes/GetAzureVMSizeCommand.cs @@ -0,0 +1,103 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; +using Microsoft.Rest.Azure; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Compute +{ + [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineSize, DefaultParameterSetName = ListVirtualMachineSizeParamSet)] + [OutputType(typeof(PSVirtualMachineSize))] + public class GetAzureVMSizeCommand : VirtualMachineSizeBaseCmdlet + { + protected const string ListVirtualMachineSizeParamSet = "ListVirtualMachineSizeParamSet"; + protected const string ListAvailableSizesForAvailabilitySet = "ListAvailableSizesForAvailabilitySet"; + protected const string ListAvailableSizesForVirtualMachine = "ListAvailableSizesForVirtualMachine"; + + [Parameter( + Mandatory = true, + Position = 0, + ParameterSetName = ListVirtualMachineSizeParamSet, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The location name.")] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + + [Parameter( + Mandatory = true, + Position = 0, + ParameterSetName = ListAvailableSizesForAvailabilitySet, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [Parameter( + Mandatory = true, + Position = 0, + ParameterSetName = ListAvailableSizesForVirtualMachine, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ParameterSetName = ListAvailableSizesForAvailabilitySet, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The availability set name.")] + [ValidateNotNullOrEmpty] + public string AvailabilitySetName { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ParameterSetName = ListAvailableSizesForVirtualMachine, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The virtual machine name.")] + [ValidateNotNullOrEmpty] + public string VMName { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + ExecuteClientAction(() => + { + IPage result = null; + + if (!string.IsNullOrEmpty(this.VMName)) + { + result = this.VirtualMachineClient.ListAvailableSizes( + this.ResourceGroupName, + this.VMName); + } + else if (!string.IsNullOrEmpty(this.AvailabilitySetName)) + { + result = this.AvailabilitySetClient.ListAvailableSizes( + this.ResourceGroupName, + this.AvailabilitySetName); + } + else + { + result = this.VirtualMachineSizeClient.List(this.Location.Canonicalize()); + } + + WriteObject(result, true); + }); + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachineSizes/VirtualMachineSizeBaseCmdlet.cs b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachineSizes/VirtualMachineSizeBaseCmdlet.cs new file mode 100644 index 000000000000..2bc1e7021b0a --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachineSizes/VirtualMachineSizeBaseCmdlet.cs @@ -0,0 +1,45 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.Compute; + +namespace Microsoft.Azure.Commands.Compute +{ + public abstract class VirtualMachineSizeBaseCmdlet : ComputeClientBaseCmdlet + { + public IVirtualMachineSizesOperations VirtualMachineSizeClient + { + get + { + return ComputeClient.ComputeManagementClient.VirtualMachineSizes; + } + } + + public IVirtualMachinesOperations VirtualMachineClient + { + get + { + return ComputeClient.ComputeManagementClient.VirtualMachines; + } + } + + public IAvailabilitySetsOperations AvailabilitySetClient + { + get + { + return ComputeClient.ComputeManagementClient.AvailabilitySets; + } + } + } +} diff --git a/src/CLU/Microsoft.Azure.Commands.Compute/project.json b/src/CLU/Microsoft.Azure.Commands.Compute/project.json new file mode 100644 index 000000000000..4fdc5cc9e3f3 --- /dev/null +++ b/src/CLU/Microsoft.Azure.Commands.Compute/project.json @@ -0,0 +1,59 @@ +{ + "version": "1.0.0-*", + "description": "Microsoft Azure Compute Cmdlets", + "authors": [ "huangpf, markcowl, hovsepm, haocs" ], + "tags": [ "" ], + "projectUrl": "", + "licenseUrl": "", + "frameworks": { + "dnxcore50": { + "dependencies": { + "Microsoft.NETCore": "5.0.1-beta-23516", + "Microsoft.NETCore.Platforms": "1.0.1-beta-23516", + "Microsoft.CSharp": "4.0.1-beta-23516" + } + } + }, + "dependencies": { + "System.Linq": "4.0.1-beta-23516", + "Microsoft.CLU": "1.0.0", + "Commands.Common": "", + "Commands.Common.Authentication": "", + "Commands.Common.Storage": "", + "Commands.ResourceManager.Common": "", + "Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha", + "Microsoft.Rest.ClientRuntime": "1.8.0", + "Newtonsoft.Json": "7.0.1", + "System.Collections": "4.0.11-beta-23516", + "System.Collections.Concurrent": "4.0.11-beta-23516", + "System.Diagnostics.TraceSource": "4.0.0-beta-23516", + "System.Diagnostics.Tracing": "4.0.21-beta-23516", + "System.IO": "4.0.11-beta-23516", + "System.IO.FileSystem": "4.0.1-beta-23516", + "System.Net.Http": "4.0.1-beta-23516", + "System.Net.WebHeaderCollection": "4.0.1-beta-23516", + "System.Reflection": "4.1.0-beta-23516", + "System.Reflection.Extensions": "4.0.1-beta-23516", + "System.Reflection.Primitives": "4.0.1-beta-23516", + "System.Reflection.TypeExtensions": "4.1.0-beta-23516", + "System.Runtime": "4.0.21-beta-23516", + "System.Runtime.Extensions": "4.0.11-beta-23516", + "System.Runtime.Serialization.Json": "4.0.1-beta-23516", + "System.Runtime.Serialization.Xml": "4.1.0-beta-23516", + "System.Security.Cryptography.Algorithms": "4.0.0-beta-23516", + "System.Security.Cryptography.X509Certificates": "4.0.0-beta-23516", + "System.Text.Encoding": "4.0.11-beta-23516", + "System.Text.Encoding.Extensions": "4.0.11-beta-23516", + "System.Threading": "4.0.11-beta-23516", + "System.Threading.Tasks": "4.0.11-beta-23516", + "System.Threading.Thread": "4.0.0-beta-23516", + "System.Xml.XmlDocument": "4.0.1-beta-23516", + "System.Xml.XPath.XmlDocument": "4.0.1-beta-23516", + "WindowsAzure.Storage": "6.1.1-preview", + "Microsoft.Azure.Management.Compute": "11.0.0-prerelease", + "Microsoft.Azure.Management.Network": "3.0.3-preview", + "Microsoft.Azure.Management.Storage": "4.0.0-preview", + "AutoMapper": "4.1.1" + }, + "compilationOptions": {"emitEntryPoint": true} +} diff --git a/src/CLU/Microsoft.Azure.Commands.Resources.Test/ResourceGroupDeployments/NewAzureResourceGroupDeploymentCommandTests.cs b/src/CLU/Microsoft.Azure.Commands.Resources.Test/ResourceGroupDeployments/NewAzureResourceGroupDeploymentCommandTests.cs index 218b82dbc3d9..91481ab5b661 100644 --- a/src/CLU/Microsoft.Azure.Commands.Resources.Test/ResourceGroupDeployments/NewAzureResourceGroupDeploymentCommandTests.cs +++ b/src/CLU/Microsoft.Azure.Commands.Resources.Test/ResourceGroupDeployments/NewAzureResourceGroupDeploymentCommandTests.cs @@ -40,7 +40,7 @@ public class NewAzureResourceGroupDeploymentCommandTests : RMTestBase private string templateFile = @"Resources\sampleTemplateFile.json"; - private string storageAccountName = "myStorageAccount"; + //private string storageAccountName = "myStorageAccount"; public NewAzureResourceGroupDeploymentCommandTests() { diff --git a/tools/CLU/BuildAndInstallClu.bat b/tools/CLU/BuildAndInstallClu.bat index 690accaa545d..4d4ae2c99a16 100644 --- a/tools/CLU/BuildAndInstallClu.bat +++ b/tools/CLU/BuildAndInstallClu.bat @@ -22,6 +22,7 @@ echo ^(Get-Content "%mscluCfg%"^) ^| ForEach-Object { $_ -replace "TOFILL", "%ro %root%\drop\clurun\win7-x64\clurun.exe --install Microsoft.Azure.Commands.Resources.Cmdlets %root%\drop\clurun\win7-x64\clurun.exe --install Microsoft.Azure.Commands.Websites %root%\drop\clurun\win7-x64\clurun.exe --install Microsoft.Azure.Commands.Management.Storage +%root%\drop\clurun\win7-x64\clurun.exe --install Microsoft.Azure.Commands.Compute REM setup osx and linux bits which can be xcopied and run. REM note, for known nuget bugs, skip --install by copying over cmdlet packages. @@ -35,4 +36,4 @@ copy /Y %root%\drop\clurun\win7-x64\azure.lx %root%\drop\clurun\ubuntu.14.04-x64 copy /Y %root%\drop\clurun\win7-x64\msclu.cfg %root%\drop\clurun\ubuntu.14.04-x64 copy /Y %~dp0\azure.sh %root%\drop\clurun\ubuntu.14.04-x64 -copy /Y %~dp0\azure %root%\drop\clurun\win7-x64 \ No newline at end of file +copy /Y %~dp0\azure %root%\drop\clurun\win7-x64