From 0a53a4955bd888e4320cc076c91a30f067c1a0bd Mon Sep 17 00:00:00 2001 From: markcowl Date: Wed, 7 Oct 2015 16:46:35 -0700 Subject: [PATCH 1/2] Add back removed resourcemanager startups cript --- .../GetAzureResourceGroupCommand.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ResourceManager/Resources/Commands.Resources/ResourceGroups/GetAzureResourceGroupCommand.cs b/src/ResourceManager/Resources/Commands.Resources/ResourceGroups/GetAzureResourceGroupCommand.cs index 1b1bc0c7925f..4de3b4d03ea1 100644 --- a/src/ResourceManager/Resources/Commands.Resources/ResourceGroups/GetAzureResourceGroupCommand.cs +++ b/src/ResourceManager/Resources/Commands.Resources/ResourceGroups/GetAzureResourceGroupCommand.cs @@ -14,7 +14,10 @@ using Microsoft.Azure.Commands.Resources.Models; using System.Collections.Generic; +using System.IO; using System.Management.Automation; +using System.Reflection; +using Microsoft.Azure.Common.Authentication; namespace Microsoft.Azure.Commands.Resources { @@ -22,7 +25,7 @@ namespace Microsoft.Azure.Commands.Resources /// Filters resource groups. /// [Cmdlet(VerbsCommon.Get, "AzureRmResourceGroup", DefaultParameterSetName = ResourceGroupNameParameterSet), OutputType(typeof(List))] - public class GetAzureResourceGroupCommand : ResourcesBaseCmdlet + public class GetAzureResourceGroupCommand : ResourcesBaseCmdlet, IModuleAssemblyInitializer { /// /// List resources group by name parameter set. @@ -57,5 +60,25 @@ protected override void ProcessRecord() ResourcesClient.FilterResourceGroups(name: this.Name, tag: null, detailed: false, location: this.Location), true); } + + /// + /// Load global aliases and script cmdlets for ARM + /// + public void OnImport() + { + try + { + System.Management.Automation.PowerShell invoker = null; + invoker = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace); + invoker.AddScript(File.ReadAllText(FileUtilities.GetContentFilePath( + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), + "ResourceManagerStartup.ps1"))); + invoker.Invoke(); + } + catch + { + // This may throw exception for tests, ignore. + } + } } } \ No newline at end of file From 313c26eaa0dc32cb8950469cf35a100634966431 Mon Sep 17 00:00:00 2001 From: markcowl Date: Wed, 7 Oct 2015 16:55:19 -0700 Subject: [PATCH 2/2] Updating scripts for new module split --- .../ResourceManagerStartup.ps1 | 14 ----------- .../Sql/Commands.Sql/Commands.Sql.csproj | 3 +++ .../Server/Cmdlet/GetAzureSqlServer.cs | 25 ++++++++++++++++++- .../Sql/Commands.Sql/SqlStartup.ps1 | 22 ++++++++++++++++ 4 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 src/ResourceManager/Sql/Commands.Sql/SqlStartup.ps1 diff --git a/src/ResourceManager/Resources/Commands.Resources/ResourceManagerStartup.ps1 b/src/ResourceManager/Resources/Commands.Resources/ResourceManagerStartup.ps1 index bdb140883a2c..3c8c12e400ab 100644 --- a/src/ResourceManager/Resources/Commands.Resources/ResourceManagerStartup.ps1 +++ b/src/ResourceManager/Resources/Commands.Resources/ResourceManagerStartup.ps1 @@ -12,20 +12,6 @@ # limitations under the License. # ---------------------------------------------------------------------------------- -@{ - # Sql aliases - "Get-AzureRmSqlDatabaseServerAuditingPolicy" = "Get-AzureRmSqlServerAuditingPolicy"; - "Remove-AzureRmSqlDatabaseServerAuditing" = "Remove-AzureRmSqlServerAuditing"; - "Set-AzureRmSqlDatabaseServerAuditingPolicy" = "Set-AzureRmSqlServerAuditingPolicy"; - "Use-AzureRmSqlDatabaseServerAuditingPolicy" = "Use-AzureRmSqlServerAuditingPolicy"; - - # Storage aliases - "Get-AzureRmStorageContainerAcl" = "Get-AzureRmStorageContainer"; - "Start-CopyAzureStorageBlob" = "Start-AzureRmStorageBlobCopy"; - "Stop-CopyAzureStorageBlob" = "Stop-AzureRmStorageBlobCopy"; -}.GetEnumerator() | Select @{Name='Name'; Expression={$_.Key}}, @{Name='Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias" - - # Authorization script commandlet that builds on top of existing Insights comandlets. # This commandlet gets all events for the "Microsoft.Authorization" resource provider by calling the "Get-AzureRmResourceProviderLog" commandlet diff --git a/src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj b/src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj index 8a7b9430fb63..7046ecef47c5 100644 --- a/src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj +++ b/src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj @@ -234,6 +234,9 @@ + + PreserveNewest + diff --git a/src/ResourceManager/Sql/Commands.Sql/Server/Cmdlet/GetAzureSqlServer.cs b/src/ResourceManager/Sql/Commands.Sql/Server/Cmdlet/GetAzureSqlServer.cs index ea570c9fc74b..7e0bebfd8d1b 100644 --- a/src/ResourceManager/Sql/Commands.Sql/Server/Cmdlet/GetAzureSqlServer.cs +++ b/src/ResourceManager/Sql/Commands.Sql/Server/Cmdlet/GetAzureSqlServer.cs @@ -13,8 +13,11 @@ // ---------------------------------------------------------------------------------- using System.Collections.Generic; +using System.IO; using System.Management.Automation; +using System.Reflection; using Microsoft.Azure.Commands.Sql.Server.Model; +using Microsoft.Azure.Common.Authentication; namespace Microsoft.Azure.Commands.Sql.Server.Cmdlet { @@ -22,7 +25,7 @@ namespace Microsoft.Azure.Commands.Sql.Server.Cmdlet /// Defines the Get-AzureRmSqlServer cmdlet /// [Cmdlet(VerbsCommon.Get, "AzureRmSqlServer", ConfirmImpact = ConfirmImpact.None)] - public class GetAzureSqlServer : AzureSqlServerCmdletBase + public class GetAzureSqlServer : AzureSqlServerCmdletBase, IModuleAssemblyInitializer { /// /// Gets or sets the name of the database server to use. @@ -74,5 +77,25 @@ protected override IEnumerable ApplyUserInputToModel(IEnume { return model; } + + /// + /// Add Sql aliases + /// + public void OnImport() + { + try + { + System.Management.Automation.PowerShell invoker = null; + invoker = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace); + invoker.AddScript(File.ReadAllText(FileUtilities.GetContentFilePath( + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), + "SqlStartup.ps1"))); + invoker.Invoke(); + } + catch + { + // This may throw exception for tests, ignore. + } + } } } diff --git a/src/ResourceManager/Sql/Commands.Sql/SqlStartup.ps1 b/src/ResourceManager/Sql/Commands.Sql/SqlStartup.ps1 new file mode 100644 index 000000000000..d1624c618418 --- /dev/null +++ b/src/ResourceManager/Sql/Commands.Sql/SqlStartup.ps1 @@ -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. +# ---------------------------------------------------------------------------------- + +@{ + # Sql aliases + "Get-AzureRmSqlDatabaseServerAuditingPolicy" = "Get-AzureRmSqlServerAuditingPolicy"; + "Remove-AzureRmSqlDatabaseServerAuditing" = "Remove-AzureRmSqlServerAuditing"; + "Set-AzureRmSqlDatabaseServerAuditingPolicy" = "Set-AzureRmSqlServerAuditingPolicy"; + "Use-AzureRmSqlDatabaseServerAuditingPolicy" = "Use-AzureRmSqlServerAuditingPolicy"; +}.GetEnumerator() | Select @{Name='Name'; Expression={$_.Key}}, @{Name='Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias" +