共用方式為


Remove-Alias

從目前的會話移除別名。

語法

Remove-Alias
      [-Name] <String[]>
      [-Scope <String>]
      [-Force]
      [<CommonParameters>]

Description

Remove-Alias Cmdlet 會移除當前 PowerShell 會話中的別名。 若要移除 Option 屬性設定為 ReadOnly的別名,請使用 Force 參數。

Remove-Alias Cmdlet 是在 PowerShell 6.0 中引進的。

範例

範例 1 - 移除別名

此範例會移除名為 del 的別名,此別名代表 Remove-Item Cmdlet。

Remove-Alias -Name del

範例 2 - 移除所有非常數別名

此範例會從目前的PowerShell工作階段中移除所有別名,但 Options 屬性設定為 Constant的別名除外。 執行命令之後,別名可在其他 PowerShell 工作階段或新的 PowerShell 會話中使用。

Get-Alias | Where-Object { $_.Options -ne "Constant" } | Remove-Alias -Force

Get-Alias 取得 PowerShell 工作階段中的所有別名,然後將物件傳送至管線。 Where-Object 使用腳本區塊,而自動變數 ($_) 和 Options 屬性則代表目前的管線物件。 -ne (不相等) 運算符會選取沒有設定為 常數Options 值的物件。 Remove-Alias 會使用 Force 參數,從 PowerShell 會話移除別名,包括唯讀別名。 Force 參數無法移除 常數 別名。

參數

-Force

表示 Cmdlet 會移除別名,包括將 Option 屬性設定為 ReadOnly的別名。 Force 參數無法移除 Option 屬性設定為 Constant的別名。

類型:SwitchParameter
Position:Named
預設值:False
必要:False
接受管線輸入:False
接受萬用字元:False

-Name

指定要移除的別名名稱。

類型:String[]
Position:0
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-Scope

只會影響指定範圍中的別名。 預設範圍 本機。 如需詳細資訊,請參閱 about_Scopes

此參數可接受的值為:

  • Global
  • Local
  • Script
  • 相對於目前範圍的數字(0 到範圍的總數,其中0是目前的範圍,1是其父系)
類型:String
Position:Named
預設值:Local
必要:False
接受管線輸入:False
接受萬用字元:False

輸入

String[]

您可以使用管線將別名物件傳送至這個 Cmdlet。

輸出

None

此 Cmdlet 不會傳回任何輸出。

備註

變更只會影響目前的範圍。 若要從所有會話中移除別名,請將 Remove-Alias 命令新增至 PowerShell 配置檔。

如需詳細資訊,請參閱 about_Aliases