Remove-Alias
从当前会话中删除别名。
语法
Default (默认值)
Remove-Alias
    [-Name] <String[]>
    [-Scope <String>]
    [-Force]
    [<CommonParameters>]
说明
              Remove-Alias cmdlet 从当前 PowerShell 会话中删除别名。 若要删除 Option 属性设置为 ReadOnly的别名,请使用 Force 参数。
PowerShell 6.0 中引入了 Remove-Alias cmdlet。
示例
示例 1 - 删除别名
此示例删除一个名为 del 的别名,该别名表示 Remove-Item cmdlet。
Remove-Alias -Name del
示例 2 - 删除所有非常量别名
本示例从当前 PowerShell 会话中删除所有别名,Options 属性设置为 常量的别名除外。 运行命令后,别名在其他 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
指示 cmdlet 删除别名,包括 Option 属性设置为 ReadOnly的别名。 Force 参数无法删除 Option 属性设置为 常量的别名。
参数属性
| 类型: | SwitchParameter | 
| 默认值: | False | 
| 支持通配符: | False | 
| 不显示: | False | 
参数集
(All)
| Position: | Named | 
| 必需: | False | 
| 来自管道的值: | False | 
| 来自管道的值(按属性名称): | False | 
| 来自剩余参数的值: | False | 
-Name
指定要删除的别名的名称。
参数属性
| 类型: | String[] | 
| 默认值: | None | 
| 支持通配符: | False | 
| 不显示: | False | 
参数集
(All)
| Position: | 0 | 
| 必需: | True | 
| 来自管道的值: | True | 
| 来自管道的值(按属性名称): | True | 
| 来自剩余参数的值: | False | 
-Scope
仅影响指定作用域中的别名。 默认范围 本地。 有关详细信息,请参阅 about_Scopes。
此参数的可接受值为:
- Global
- Local
- Script
- 相对于当前范围的数字(0 到范围的数目,其中 0 是当前范围,1 是它的父范围)
参数属性
| 类型: | String | 
| 默认值: | Local | 
| 支持通配符: | False | 
| 不显示: | False | 
参数集
(All)
| Position: | Named | 
| 必需: | False | 
| 来自管道的值: | False | 
| 来自管道的值(按属性名称): | False | 
| 来自剩余参数的值: | False | 
CommonParameters
此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters。
输入
String
您可以将别名对象通过管道传输到 Remove-Alias。
输出
None
此 cmdlet 不返回任何输出。
备注
更改仅影响当前范围。 若要从所有会话中删除别名,请将 Remove-Alias 命令添加到 PowerShell 配置文件。
有关详细信息,请参阅 about_Aliases。