PowerTip of the Day-Finding Invalid Aliases

本文介绍如何使用Powershell命令检查系统中设置的所有别名,并找出那些指向无效目标的别名。通过简单的脚本即可确保所有别名的有效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址:http://app.en25.com/e/es.aspx?s=1403&e=4778&elq=baf9b44a60364f3fbf25d7590e9cb761

原文:

When you create new Aliases with Set-Alias, PowerShell does not check whether the target you specify is valid. Instead, this is checked only when you use the alias. This line can help you to find all aliases with invalid targets:

Get-Alias | ForEach-Object { if (!(Get-Command $_.Definition -ea SilentlyContinue)) {$_}}

If it returns nothing, then all is fine.

 

翻译:

当使用Set-Alias创建一个别名的时候,Powershell不会检查这个别名是否合法。然而,只有用到的时候才会被检查。下面的代码可以帮助你找到所有不合法的别名:

Get-Alias | ForEach-Object { if (!(Get-Command $_.Definition -ea SilentlyContinue)) {$_}}

如果什么也不返回,就说明都合法。

 

笔记:

-ea = –ErrorAction

Get-Command 用于检索所有可用 cmdlet 的列表

转载于:https://www.cnblogs.com/aspnetx/archive/2010/06/23/1763829.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值