1. 简化参数名称
Powershell 并不强制要求输入完成的参数名称。例如,你可以通过输入 -comp 来代替 -computer,但是你必须保证你所输入的字母足够让系统识别出你所输入的字母代表的是哪一个参数。
在输入这些最少部分的参数以后,可以按tab键来不起参数名。
2. 参数名称别名
因为参数的别名在没有帮助文件且不易识别,本人并不十分喜欢这种用法,因此这部分不做过多笔记。
3. 位置参数
以: Get-ChildItem 为例。
SYNTAX
Get-ChildItem [[-Path] <String[]>] [[-Filter] <String>] [-Attributes {ReadOnly | Hidden | System | Directory | Archive | Device
| Normal | Temporary | SparseFile | ReparsePoint | Compressed | Offline | NotContentIndexed | Encrypted | IntegrityStream |
NoScrubData}] [-Depth <UInt32>] [-Directory] [-Exclude <String[]>] [-File] [-Force] [-Hidden] [-Include <String[]>] [-Name]
[-ReadOnly] [-Recurse] [-System] [-UseTransaction] [<CommonParameters>]
通过其语法可以看出, -Path 以及 -Filter 参数名称在中括号内,因此属于位置参数, 通过更详细的帮助文档 (可以通过 help Get-ChildItem -full 来获得)
通过其参数说明:
-Path <String[]>
Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory (.).
Required? false
Position? 0
Default value Current directory
Accept pipeline input? True (ByPropertyName, ByValue)
Accept wildcard characters? false
可知, -Path参数位置是1,对于位置参数来说,你无需提供其参数名,只需在正确的位置提供其参数值即可。
例如:
PS C:\WINDOWS\system32> Get-ChildItem D:\Shaw
Directory: D:\Shaw
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/22/2018 9:30 AM 20180222BackGroundCheck
d----- 2/24/2018 6:21 PM bodybuilding
d----- 12/5/2017 10:44 AM Cbitlocker
d----- 12/5/2017 12:34 PM OneNote
d----- 5/22/2018 4:59 PM Pic
d----- 1/15/2018 4:30 PM Study
d----- 12/7/2017 8:51 AM Training
由于使用位置参数你必须记住每一个位置所代表的参数,且正确输入参数值的顺序,很容易出现问题,因此不推荐使用位置参数。