PowerTip of the DayFinding Invalid Aliases

原文地址: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/p/1763829.html