Skip to content

Commit d1f225b

Browse files
committed
Merge pull request Azure#1082 from markcowl/resourcescript
Adding back alias and script cmdlet definitions for resource and sql modules
2 parents 5c624bc + 7fb3abc commit d1f225b

File tree

5 files changed

+73
-16
lines changed

5 files changed

+73
-16
lines changed

src/ResourceManager/Resources/Commands.Resources/ResourceGroups/GetAzureResourceGroupCommand.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414

1515
using Microsoft.Azure.Commands.Resources.Models;
1616
using System.Collections.Generic;
17+
using System.IO;
1718
using System.Management.Automation;
19+
using System.Reflection;
20+
using Microsoft.Azure.Common.Authentication;
1821

1922
namespace Microsoft.Azure.Commands.Resources
2023
{
2124
/// <summary>
2225
/// Filters resource groups.
2326
/// </summary>
2427
[Cmdlet(VerbsCommon.Get, "AzureRmResourceGroup", DefaultParameterSetName = ResourceGroupNameParameterSet), OutputType(typeof(List<PSResourceGroup>))]
25-
public class GetAzureResourceGroupCommand : ResourcesBaseCmdlet
28+
public class GetAzureResourceGroupCommand : ResourcesBaseCmdlet, IModuleAssemblyInitializer
2629
{
2730
/// <summary>
2831
/// List resources group by name parameter set.
@@ -57,5 +60,25 @@ protected override void ProcessRecord()
5760
ResourcesClient.FilterResourceGroups(name: this.Name, tag: null, detailed: false, location: this.Location),
5861
true);
5962
}
63+
64+
/// <summary>
65+
/// Load global aliases and script cmdlets for ARM
66+
/// </summary>
67+
public void OnImport()
68+
{
69+
try
70+
{
71+
System.Management.Automation.PowerShell invoker = null;
72+
invoker = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
73+
invoker.AddScript(File.ReadAllText(FileUtilities.GetContentFilePath(
74+
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
75+
"ResourceManagerStartup.ps1")));
76+
invoker.Invoke();
77+
}
78+
catch
79+
{
80+
// This may throw exception for tests, ignore.
81+
}
82+
}
6083
}
6184
}

src/ResourceManager/Resources/Commands.Resources/ResourceManagerStartup.ps1

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@
1212
# limitations under the License.
1313
# ----------------------------------------------------------------------------------
1414

15-
@{
16-
# Sql aliases
17-
"Get-AzureRmSqlDatabaseServerAuditingPolicy" = "Get-AzureRmSqlServerAuditingPolicy";
18-
"Remove-AzureRmSqlDatabaseServerAuditing" = "Remove-AzureRmSqlServerAuditing";
19-
"Set-AzureRmSqlDatabaseServerAuditingPolicy" = "Set-AzureRmSqlServerAuditingPolicy";
20-
"Use-AzureRmSqlDatabaseServerAuditingPolicy" = "Use-AzureRmSqlServerAuditingPolicy";
21-
22-
# Storage aliases
23-
"Get-AzureRmStorageContainerAcl" = "Get-AzureRmStorageContainer";
24-
"Start-CopyAzureStorageBlob" = "Start-AzureRmStorageBlobCopy";
25-
"Stop-CopyAzureStorageBlob" = "Stop-AzureRmStorageBlobCopy";
26-
}.GetEnumerator() | Select @{Name='Name'; Expression={$_.Key}}, @{Name='Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias"
27-
28-
2915
# Authorization script commandlet that builds on top of existing Insights comandlets.
3016
# This commandlet gets all events for the "Microsoft.Authorization" resource provider by calling the "Get-AzureRmResourceProviderLog" commandlet
3117

src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@
234234
<Compile Include="TransparentDataEncryption\Model\AzureSqlDatabaseTransparentDataEncryptionModel.cs" />
235235
<Compile Include="TransparentDataEncryption\Services\AzureSqlDatabaseTransparentDataEncryptionAdapter.cs" />
236236
<Compile Include="TransparentDataEncryption\Services\AzureSqlDatabaseTransparentDataEncryptionCommunicator.cs" />
237+
<None Include="SqlStartup.ps1">
238+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
239+
</None>
237240
</ItemGroup>
238241
<ItemGroup>
239242
<EmbeddedResource Include="Properties\Resources.resx">

src/ResourceManager/Sql/Commands.Sql/Server/Cmdlet/GetAzureSqlServer.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System.Collections.Generic;
16+
using System.IO;
1617
using System.Management.Automation;
18+
using System.Reflection;
1719
using Microsoft.Azure.Commands.Sql.Server.Model;
20+
using Microsoft.Azure.Common.Authentication;
1821

1922
namespace Microsoft.Azure.Commands.Sql.Server.Cmdlet
2023
{
2124
/// <summary>
2225
/// Defines the Get-AzureRmSqlServer cmdlet
2326
/// </summary>
2427
[Cmdlet(VerbsCommon.Get, "AzureRmSqlServer", ConfirmImpact = ConfirmImpact.None)]
25-
public class GetAzureSqlServer : AzureSqlServerCmdletBase
28+
public class GetAzureSqlServer : AzureSqlServerCmdletBase, IModuleAssemblyInitializer
2629
{
2730
/// <summary>
2831
/// Gets or sets the name of the database server to use.
@@ -74,5 +77,25 @@ protected override IEnumerable<AzureSqlServerModel> ApplyUserInputToModel(IEnume
7477
{
7578
return model;
7679
}
80+
81+
/// <summary>
82+
/// Add Sql aliases
83+
/// </summary>
84+
public void OnImport()
85+
{
86+
try
87+
{
88+
System.Management.Automation.PowerShell invoker = null;
89+
invoker = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
90+
invoker.AddScript(File.ReadAllText(FileUtilities.GetContentFilePath(
91+
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
92+
"SqlStartup.ps1")));
93+
invoker.Invoke();
94+
}
95+
catch
96+
{
97+
// This may throw exception for tests, ignore.
98+
}
99+
}
77100
}
78101
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
@{
16+
# Sql aliases
17+
"Get-AzureRmSqlDatabaseServerAuditingPolicy" = "Get-AzureRmSqlServerAuditingPolicy";
18+
"Remove-AzureRmSqlDatabaseServerAuditing" = "Remove-AzureRmSqlServerAuditing";
19+
"Set-AzureRmSqlDatabaseServerAuditingPolicy" = "Set-AzureRmSqlServerAuditingPolicy";
20+
"Use-AzureRmSqlDatabaseServerAuditingPolicy" = "Use-AzureRmSqlServerAuditingPolicy";
21+
}.GetEnumerator() | Select @{Name='Name'; Expression={$_.Key}}, @{Name='Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias"
22+

0 commit comments

Comments
 (0)