Parameters PowerShell-作为参数族

Parameters PowerShell-作为参数族,parameters,powershell-2.0,Parameters,Powershell 2.0,如何查找或列出PowerShell的参数族 到目前为止,我找到了-as类型,例如-as[Int] 我也找到了——烟灰缸 我的问题是,还有哪些其他参数可用?如果您投入任何努力,这可能会有一个更优雅的解决方案: PS Home:\> gcm | where { $_.CommandType -eq 'Cmdlet' } | foreach { $_ | Add-Member -PassThru NoteProperty AsParameters ($_.Parameters.GetEnumer

如何查找或列出PowerShell的参数族

到目前为止,我找到了-as类型,例如-as[Int] 我也找到了——烟灰缸


我的问题是,还有哪些其他参数可用?

如果您投入任何努力,这可能会有一个更优雅的解决方案:

PS Home:\> gcm | where { $_.CommandType -eq 'Cmdlet' } | foreach { $_ | Add-Member -PassThru NoteProperty AsParameters ($_.Parameters.GetEnumerator() | ? {$_.Key -cmatch '^As([A-Z]|$)'} | % { $_.Key }) } | where { $_.AsParameters } | select Name,AsParameters

Name                   AsParameters
----                   ------------
ConvertTo-Html         As
ConvertTo-SecureString AsPlainText
ConvertTo-Xml          As
Export-Alias           As
Get-EventLog           {AsBaseObject, AsString}
Get-Unique             AsString
Get-WmiObject          AsJob
Group-Object           {AsHashTable, AsString}
Import-Module          AsCustomObject
Invoke-Command         AsJob
Invoke-WmiMethod       AsJob
New-Module             AsCustomObject
Read-Host              AsSecureString
Remove-WmiObject       AsJob
Restart-Computer       AsJob
Set-WmiInstance        AsJob
Stop-Computer          AsJob
Test-Connection        AsJob
代码剖析:

# find all commands
Get-Command |
  # that are cmdlets (exclude aliases or functions)
  Where-Object { $_.CommandType -eq 'Cmdlet' } |
  ForEach-Object {
    # Add another property that contains all parameters
    # that starts with 'As' – I use a regex here to exclude
    # parameters like -Assembly
    $_ | Add-Member -PassThru NoteProperty AsParameters (
      $_.Parameters.GetEnumerator() |
        Where-Object { $_.Key -cmatch '^As([A-Z]|$)' } |
        ForEach-Object { $_.Key }
    )
  } |
  # Exclude commands that don't have parameters that start with 'As'
  Where-Object { $_.AsParameters } |
  Select-Object Name,AsParameters

精彩的剧本。现在我可以看到,它是一个具有-ashtable参数的Group对象。Get Eventlog还有一个有趣的参数-AsBaseObject