diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs index 8ae43a6e4fd..3428b377da3 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System; using System.Management.Automation; using System.Management.Automation.Internal; @@ -82,6 +83,16 @@ protected override void ProcessRecord() AliasInfo result = null; + if (string.Equals(newAlias.Name, newAlias.Definition, StringComparison.OrdinalIgnoreCase)) + { + PSArgumentException e = PSTraceSource.NewArgumentException("Value", NewObjectStrings.InvalidValue, newAlias.Name); + WriteError( + new ErrorRecord( + e.ErrorRecord, + e)); + return; + } + try { if (string.IsNullOrEmpty(Scope)) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs index 6c0007fa2a2..2732f1a4381 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System; using System.Management.Automation; using System.Management.Automation.Internal; @@ -42,6 +43,16 @@ protected override void ProcessRecord() AliasInfo result = null; + if (string.Equals(aliasToSet.Name, aliasToSet.Definition, StringComparison.OrdinalIgnoreCase)) + { + PSArgumentException e = PSTraceSource.NewArgumentException("Value", NewObjectStrings.InvalidValue, aliasToSet.Name); + WriteError( + new ErrorRecord( + e.ErrorRecord, + e)); + return; + } + try { if (string.IsNullOrEmpty(Scope))