2012-06-22 44 views
1

我使用PowerShell的3.0 的RC我想知道如何在返回的对象(在Get-Module -ListAvailable结果像“ExportedCommands”属性)查询和显示列表:查询子集

PS H:\> get-module -ListAvailable 


    Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules 


ModuleType Name        ExportedCommands 
---------- ----        ---------------- 
Manifest AppLocker       {Set-AppLockerPolicy, Get-AppLockerPolicy, Test-AppLockerPolicy, Get-... 
Manifest BitsTransfer      {Add-BitsFile, Remove-BitsTransfer, Complete-BitsTransfer, Get-BitsTr... 
Manifest CimCmdlets       {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, Get-CimSes... 

回答

1

嗯..这一切都取决于两个因素:

  • 什么你的收集实际上是(在这种命令 - 你可以字典)
  • 你想看到它或行事就可以了。

在这种情况下,知道这是一本字典收藏,您可以:

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参数)。

0

OP的帖子中的问题是,默认情况下,PowerShell仅显示重复此类型的组中的前N个值。因此,对于导出的命令,您只能看到前4个(默认值为4)。要改变这一点,只需为变量$ FormatEnumerationLimit设置一个更高的值即可。并根据格式,表格的能力,你可能还需要指定-wrap上明确管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} 

...剪断为了简洁**