0
我如何才能找到或列表PowerShell的-as家庭的參數?PowerShell的-as家庭
到目前爲止,我發現-as類型如-as [INT] 另外我發現-asHashTable
我的問題是什麼其他-as參數有哪些?
我如何才能找到或列表PowerShell的-as家庭的參數?PowerShell的-as家庭
到目前爲止,我發現-as類型如-as [INT] 另外我發現-asHashTable
我的問題是什麼其他-as參數有哪些?
這也許可能有如果把任何努力來成爲一個更優雅的解決方案:
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
一個精彩的劇本。我現在可以看到,這是集團的對象具有-AsHashTable參數。還可以獲得-事件日誌有一個名爲一個有趣的參數-AsBaseObject – 2010-07-17 21:47:58