Powershell cmdlet参数的较短版本 [英] Shorter versions of powershell cmdlet parameters
问题描述
考虑到我的研究,我认为完成以下任何一项工作都不容易.但是,作为最后的选择,我想我会在这里检查.
Given my research, I don't believe the following is easily accomplished, if at all. As a last resort, however, I figured I'd check here.
在Powershell 2.0中,我想要一种将参数的(烦人的)长名称简化为各种cmdlet的方法.我希望绝对控制速记版本的外观. (而不是PS使用的任何参数缩写方案的从属.)
In Powershell 2.0, I'd like a way to reduce the (annoyingly) long names of parameters to various cmdlets. I would like absolute control over what the shorthand version looks like. (As opposed to being a slave to whatever parameter abbreviation scheme PS uses.)
例如,我希望能够做这样的事情:
So, for example, I'd like to be able to do something like this:
# Command goes on this first line to alias "-ForegroundColor" to "-fg"
# Command goes on this second line to alias "-BackgroundColor" to "-bg"
Wr-te-Host -fg yellow -bg black "Parameter aliases now work just like I want."
与该功能最接近的是什么?如何?我无法使用获取有关about_parameters的帮助"找到有关参数缩写的任何信息.
What's the closest I can get to this functionality, and how? I was not able to find anything regarding parameter abbreviation using 'get-help about_parameters'.
谢谢!
推荐答案
检查此脚本: Get-Parameter.ps1
点源它并执行以下命令,它提供了有关命令参数的大量信息.查看别名列,它将显示所有内置参数别名以及计算可用于参数的最短名称:
dot-source it and execute the following, it gives a wealth of information about a command parameters. Take a look at the aliases column, it will show all built-in parameter aliases as well as calculates the shortest name you can use for a parameter:
PS > Get-Parameter Write-Host
Command: Microsoft.PowerShell.Utility/Write-Host
Set: Default
Name Aliases Position Mandatory Pipeline ByName Provider Type
---- ------- -------- --------- -------- ------ -------- ----
BackgroundColor {b} Named False False False All ConsoleColor
ForegroundColor {f} Named False False False All ConsoleColor
NoNewline {n} Named False False False All SwitchParameter
Object {obj} 0 False True False All Object
Separator {s} Named False False False All Object
这篇关于Powershell cmdlet参数的较短版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!