PowerShell自定義函數(shù)的參數(shù)沒(méi)有具體的命名規(guī)則,那么怎么做才能讓參數(shù)的命名更加科學(xué)可持續(xù)。
我們應(yīng)該怎么來(lái)命名函數(shù)的參數(shù)名稱呢?有沒(méi)有一個(gè)可供參考的列表?當(dāng)然微軟沒(méi)有給出來(lái)。但是我們可以來(lái)理一個(gè)列表出來(lái)。微軟自帶了大量的cmdlet,這些cmdlet使用的參數(shù)有什么規(guī)律呢?我們用下面一段命令來(lái)統(tǒng)計(jì)一下。
復(fù)制代碼 代碼如下:
Get-Command -CommandType Cmdlet |
ForEach-Object { $_.Parameters } |
ForEach-Object { $_.Keys } |
Group-Object -NoElement |
Sort-Object Count, Name -Descending |
Select-Object -Skip 11 |
Where-Object { $_.Count -gt 1 }
這段代碼的作用就是把所有的cmdlet使用的參數(shù)名稱來(lái)做一個(gè)統(tǒng)計(jì),看看哪些名稱的參數(shù)用得比較多,然后按從多到少的順序做一個(gè)列表。小編這邊運(yùn)行后的結(jié)果如下:
復(fù)制代碼 代碼如下:
Count Name
----- ----
69 Force
56 InputObject
53 Credential
52 Path
48 PassThru
43 LiteralPath
35 UseTransaction
33 Exclude
32 Include
30 ComputerName
28 Filter
26 Id
14 Scope
14 Property
14 InstanceId
13 Value
13 Authentication
12 ThrottleLimit
12 Description
12 ArgumentList
10 Session
10 Encoding
9 SourceIdentifier
8 Wait
8 Namespace
8 DisplayName
8 CertificateThumbprint
8 AsJob
7 UseSSL
7 Stream
7 State
7 Port
7 NoClobber
7 Impersonation
7 FilePath
6 TypeName
6 Timeout
6 SessionOption
6 Option
6 Module
6 Message
6 LogName
6 Job
6 ConnectionUri
6 ConfigurationName
6 Command
6 Class
6 ApplicationName
6 AllowRedirection
5 View
5 Variable
5 Source
5 Recurse
5 PSProvider
5 Delimiter
4 UseDefaultCredentials
4 UseCulture
4 UICulture
4 StackName
4 ShowError
4 NewName
4 MessageData
4 Locale
4 GroupBy
4 Expand
4 EnableAllPrivileges
4 DisplayError
4 Destination
4 Depth
4 Culture
4 Count
4 Certificate
4 Category
4 CaseSensitive
4 Body
4 Authority
4 Append
4 Action
3 Width
3 Uri
3 SupportEvent
3 Server
3 SecurityDescriptorSddl
3 ScriptBlock
3 Restart
3 PSVersion
3 ProxyCredential
3 OutputBufferingMode
3 NoTypeInformation
3 NoServiceRestart
3 Newest
3 ModulesToImport
3 MemberType
3 MaxTriggerCount
3 MaximumRedirection
3 LocalCredential
3 List
3 Function
3 Forward
3 EnableNetworkAccess
3 CommandType
3 Cmdlet
3 Breakpoint
3 AsString
3 AssemblyName
3 As
2 WebSession
2 Visibility
2 Verb
2 UseSharedProcess
2 UserAgent
2 UnjoinDomainCredential
2 Unique
2 TypesToProcess
2 TypeData
2 Type
2 TransportOption
2 TransferEncoding
2 TotalCount
2 Title
2 TimeoutSec
2 ThreadOptions
2 ThreadApartmentState
2 SubscriptionId
2 Strict
2 Status
2 StartupType
2 StartupScript
2 SkipNetworkProfileCheck
2 Skip
2 ShowSecurityDescriptorUI
2 SessionVariable
2 SessionTypeOption
2 SessionType
2 SecondValue
2 Seconds
2 ScriptsToProcess
2 Script
2 RunAsCredential
2 RestorePoint
2 Resolve
2 Quiet
2 Query
2 PSSession
2 PSHost
2 ProxyUseDefaultCredent...
2 Proxy
2 ProcessorArchitecture
2 PrependPath
2 Prefix
2 PowerShellVersion
2 OutFile
2 Off
2 NotMatch
2 ModuleInfo
2 Minimum
2 Method
2 MemberName
2 MaximumReceivedObjectS...
2 MaximumReceivedDataSiz...
2 Maximum
2 LiteralName
2 ListenerOption
2 Line
2 JobName
2 InFile
2 Index
2 IdleTimeoutSec
2 Headers
2 Header
2 Guid
2 FormatTypeName
2 FormatsToProcess
2 First
2 Expression
2 EventIdentifier
2 EntryType
2 End
2 Drive
2 DisplayHint
2 DisableNameChecking
2 DisableKeepAlive
2 Delay
2 Debugger
2 Date
2 Copyright
2 ContentType
2 ConfigurationTypeName
2 CompanyName
2 CommandName
2 Column
2 CimSession
2 CimResourceUri
2 CimNamespace
2 CanonicalName
2 Before
2 AutoSize
2 Author
2 AsCustomObject
2 ApplicationBase
2 AppendPath
2 AllowClobber
2 All
2 Alias
2 After
2 AccessMode
好了,看到這個(gè)列表,我相信大家對(duì)如何設(shè)置一個(gè)參數(shù)名稱有了一定的了解了。參照這個(gè)列表上的名稱,或者就使用這個(gè)列表上的名稱,讓你的cmdlet對(duì)更易懂!
關(guān)于PowerShell函數(shù)的參數(shù)應(yīng)該怎樣命名,本文就介紹這么多,希望對(duì)您有所幫助,謝謝!
您可能感興趣的文章:- PowerShell定義函數(shù)參數(shù)的2種方法和傳參方法實(shí)例
- PowerShell函數(shù)參數(shù)指定數(shù)據(jù)類型實(shí)例
- PowerShell中給函數(shù)參數(shù)設(shè)置幫助信息的例子
- PowerShell函數(shù)參數(shù)用星號(hào)隱藏的方法
- PowerShell函數(shù)參數(shù)設(shè)置成自動(dòng)識(shí)別數(shù)據(jù)類型的例子
- PowerShell函數(shù)參數(shù)設(shè)置為即可選又必選的方法
- PowerShell函數(shù)參數(shù)使用智能提示功能例子
- PowerShell使用枚舉變量定義帶智能提示功能的函數(shù)參數(shù)