Powershell 查询子集合
我正在使用Powershell v3.0的RC 我想知道如何查询和显示返回对象中的列表(如Powershell 查询子集合,powershell,powershell-3.0,Powershell,Powershell 3.0,我正在使用Powershell v3.0的RC 我想知道如何查询和显示返回对象中的列表(如Get Module-listavable结果中的“ExportedCommands”属性): 嗯。。这完全取决于两个因素: 你的同事实际上是什么(在这个命令中,你可以使用字典) 你想看它还是按它去做 在这种情况下,知道这是一个字典集合,您可以: Get-Module -ListAvailable | Format-List Name, @{ Name = 'Exported
Get Module-listavable
结果中的“ExportedCommands”属性):
嗯。。这完全取决于两个因素:
- 你的同事实际上是什么(在这个命令中,你可以使用字典)
- 你想看它还是按它去做
Get-Module -ListAvailable |
Format-List Name, @{
Name = 'ExportedCommands'
Expression = {
$_.ExportedCommands.Keys -join "`n"
}
}
。。或者,您可以直接使用这些键,但这样会丢失对模块的跟踪。
或者您可以将其反转:
Get-Command | Sort Module | Format-Table Name -GroupBy Module
但同样:这只是为了显示数据。如果您想对其进行操作,格式-*对您没有帮助,您应该使用select(可能是wit-expand参数)。好的。。这完全取决于两个因素:
- 你的同事实际上是什么(在这个命令中,你可以使用字典)
- 你想看它还是按它去做
Get-Module -ListAvailable |
Format-List Name, @{
Name = 'ExportedCommands'
Expression = {
$_.ExportedCommands.Keys -join "`n"
}
}
。。或者,您可以直接使用这些键,但这样会丢失对模块的跟踪。
或者您可以将其反转:
Get-Command | Sort Module | Format-Table Name -GroupBy Module
但同样:这只是为了显示数据。如果您想对其进行操作,format-*对您没有帮助,您应该使用select(可能是wit-expand参数)。OP文章中的问题是,默认情况下,PowerShell只显示此类型重复组中的前N个值。因此,对于导出的命令,只能看到前4个(默认值为4)。要更改此设置,只需将更高的值设置为可变$FormatEnumerationLimit。根据格式表的功能,您可能还需要在显式管道上指定-wrap to FT,如下所示:
PSH [C:\foo]: $FormatEnumerationLimit = 99
PSH [C:\foo]: get-module -ListAvailable | ft -wrap
Directory: C:\Users\tfl.COOKHAM\Documents\WindowsPowerShell\Modules
ModuleType Name ExportedCommands
---------- ---- ----------------
Manifest Audit
Script authenticode {New-PoshCode, Get-PoshCode, Get-PoshCodeUpgrade, Get-WebFile, Set-DownloadFlag,
Remove-DownloadFlag, Get-DownloadFlag, Test-DownloadFlag, block, unblock,
Search-PoshCode}
Script DotNet {Get-Type, Get-ProgID, Get-CommandWithParameterType}
Manifest DTW.PS.FIleSystem Get-DTWFileEncoding
Manifest DTW.PS.PrettyPrinterV1 Get-DTWFileEncoding
Script EZOut {Add-FormatData, Clear-FormatData, Remove-FormatData, Out-FormatData,
Show-CustomAction, Write-FormatView, Write-CustomAction, Write-FormatTableView,
Get-FormatFile, Find-FormatView, Get-PropertySet, Add-TypeData, Clear-TypeData,
Remove-TypeData, Out-TypeData, Write-TypeView}
Script FileSystem {Copy-ToZip, Get-DuplicateFile, Get-FreeDiskSpace, Get-SHA1, New-Zip,
Mount-SpecialFolder, Rename-Drive, Resolve-ShortcutFile, Start-FileSystemWatcher}
Manifest FileTransfer {Add-BitsFile, Remove-BitsTransfer, Complete-BitsTransfer, Get-BitsTransfer,
Start-BitsTransfer, Resume-BitsTransfer, Set-BitsTransfer, Suspend-BitsTransfer}
Manifest hyperv {Add-ZIPContent, ConvertTo-Enum, Copy-ZipContent, Get-ZIPContent, Select-Item,
Select-List, Select-EnumType, Out-Tree, Select-Tree, Test-Admin,
Convert-DiskIDtoDrive, Get-FirstAvailableDriveLetter, New-Zip, Test-WMIJob,
Test-WMIResult}
Script IsePack {Add-ForeachStatement, Add-IfStatement, Add-InlineHelp, Add-IseMenu,
Add-Parameter, Add-PInvoke, Add-SwitchStatement, Close-AllOpenedFiles,
ConvertTo-ShortcutKeyTable, Copy-Colored, Copy-ColoredHTML, Export-FormatView,
Get-CurrentOpenedFileToken, Get-CurrentToken, Get-FunctionFromFile,
Get-TokenFromFile, Invoke-Line, Move-ToLastGroup, Move-ToLastPowerShellTab,
Move-ToNextGroup, Move-ToNextPowerShellTab, New-IseScript,
New-ScriptModuleFromCurrentLocation, Push-CurrentFileLocation,
Save-IseFileWithAutoName, Select-AllInFile, Select-CurrentText,
Select-CurrentTextAsCommand, Select-CurrentTextAsType,
Select-CurrentTextAsVariable, Show-HelpForCurrentSelection, Show-Member,
Show-SyntaxForCurrentCommand, Show-TypeConstructor,
Show-TypeConstructorForCurrentType, Split-IseFile, Switch-CommentOrText,
Switch-SelectedCommentOrText, Write-ColorizedHTML}
。。。为简洁起见剪掉**OP文章中的问题是,默认情况下,PowerShell只显示此类型重复组中的前N个值。因此,对于导出的命令,只能看到前4个(默认值为4)。要更改此设置,只需将更高的值设置为可变$FormatEnumerationLimit。根据格式表的功能,您可能还需要在显式管道上指定-wrap to FT,如下所示:
PSH [C:\foo]: $FormatEnumerationLimit = 99
PSH [C:\foo]: get-module -ListAvailable | ft -wrap
Directory: C:\Users\tfl.COOKHAM\Documents\WindowsPowerShell\Modules
ModuleType Name ExportedCommands
---------- ---- ----------------
Manifest Audit
Script authenticode {New-PoshCode, Get-PoshCode, Get-PoshCodeUpgrade, Get-WebFile, Set-DownloadFlag,
Remove-DownloadFlag, Get-DownloadFlag, Test-DownloadFlag, block, unblock,
Search-PoshCode}
Script DotNet {Get-Type, Get-ProgID, Get-CommandWithParameterType}
Manifest DTW.PS.FIleSystem Get-DTWFileEncoding
Manifest DTW.PS.PrettyPrinterV1 Get-DTWFileEncoding
Script EZOut {Add-FormatData, Clear-FormatData, Remove-FormatData, Out-FormatData,
Show-CustomAction, Write-FormatView, Write-CustomAction, Write-FormatTableView,
Get-FormatFile, Find-FormatView, Get-PropertySet, Add-TypeData, Clear-TypeData,
Remove-TypeData, Out-TypeData, Write-TypeView}
Script FileSystem {Copy-ToZip, Get-DuplicateFile, Get-FreeDiskSpace, Get-SHA1, New-Zip,
Mount-SpecialFolder, Rename-Drive, Resolve-ShortcutFile, Start-FileSystemWatcher}
Manifest FileTransfer {Add-BitsFile, Remove-BitsTransfer, Complete-BitsTransfer, Get-BitsTransfer,
Start-BitsTransfer, Resume-BitsTransfer, Set-BitsTransfer, Suspend-BitsTransfer}
Manifest hyperv {Add-ZIPContent, ConvertTo-Enum, Copy-ZipContent, Get-ZIPContent, Select-Item,
Select-List, Select-EnumType, Out-Tree, Select-Tree, Test-Admin,
Convert-DiskIDtoDrive, Get-FirstAvailableDriveLetter, New-Zip, Test-WMIJob,
Test-WMIResult}
Script IsePack {Add-ForeachStatement, Add-IfStatement, Add-InlineHelp, Add-IseMenu,
Add-Parameter, Add-PInvoke, Add-SwitchStatement, Close-AllOpenedFiles,
ConvertTo-ShortcutKeyTable, Copy-Colored, Copy-ColoredHTML, Export-FormatView,
Get-CurrentOpenedFileToken, Get-CurrentToken, Get-FunctionFromFile,
Get-TokenFromFile, Invoke-Line, Move-ToLastGroup, Move-ToLastPowerShellTab,
Move-ToNextGroup, Move-ToNextPowerShellTab, New-IseScript,
New-ScriptModuleFromCurrentLocation, Push-CurrentFileLocation,
Save-IseFileWithAutoName, Select-AllInFile, Select-CurrentText,
Select-CurrentTextAsCommand, Select-CurrentTextAsType,
Select-CurrentTextAsVariable, Show-HelpForCurrentSelection, Show-Member,
Show-SyntaxForCurrentCommand, Show-TypeConstructor,
Show-TypeConstructorForCurrentType, Split-IseFile, Switch-CommentOrText,
Switch-SelectedCommentOrText, Write-ColorizedHTML}
。。。剪短**