如何在powershell中列出所有已安装、可运行的cmdlet? [英] How to list all installed, runnable cmdlets in powershell?

查看:70
本文介绍了如何在powershell中列出所有已安装、可运行的cmdlet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 powershell 中列出所有已安装的、可运行的 cmdlet 和函数,但 Get-Command 列出了以某种方式在那里"但未加载且无法运行的 cmdlet.

I want to list all installed, runable cmdlets and functions in powershell but Get-Command is listing cmdlets which are somehow "there" but not loaded and not runnable.

例如,Get-Command 列出了 New-IseSnippet:

PS W:\> get-command "*-*" -CommandType Function,Cmdlet | where name -like "New-IseSnippet" | select name,module,path

Name           Module path
----           ------ ----
New-IseSnippet ISE

所以看起来我们有一个 New-IseSnippet 命令 - 让我们检查一下:

So it looks like we have a New-IseSnippet command - let's inspect it:

PS W:\> get-command New-IseSnippet
get-command : The term 'New-IseSnippet' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that 
the path is correct and try again.
At line:1 char:1
+ get-command New-IseSnippet
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-IseSnippet:String) [Get-Command], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand

不,我们可以运行它吗?:

Nope, can we run it?:

PS W:\> New-IseSnippet
New-IseSnippet : The 'New-IseSnippet' command was found in the module 'ISE', but the module could not be loaded. For more information, run 'Import-Module ISE'.
At line:1 char:1
+ New-IseSnippet
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-IseSnippet:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

没有.

我们如何只获得已安装的、可运行的命令?

How do we get only installed, runnable commands?

推荐答案

至于这个根查询...

我想列出所有已安装的、可运行的 cmdlet 和函数电源外壳

I want to list all installed, runable cmdlets and functions in powershell

... 在我的个人库中,这是我很久以前创建/组合的片段的一部分,并根据需要进行更新,正是为了这种用例.我的代码片段中还有更多内容,但是根据您的帖子,这应该可以满足您的需求.这是我在 ISE/VSCode 中的代码片段库,我可以随时使用 CTRL+J 调出它并在 ISE 中选择它,然后在 VSCode 中输入 Help 并选择它.

... In my personal library, here is part of a snippet I created/put-together, a long time ago and update as needed, for exactly this kind of use case. There is far more in my snippet, but this should get you what you are after as per your post. This being my my snippet library in ISE / VSCode, I bring it up anytime as need using CTRL+J and selecting it in the ISE and just typing Help in VSCode and selecting it.

# Get parameters, examples, full and Online help for a cmdlet or function

# Get a list of all Modules
Get-Module -ListAvailable | 
Out-GridView -PassThru -Title 'Available modules'

# Get a list of all functions
Get-Command -CommandType Function | 
Out-GridView -PassThru -Title 'Available functions'

# Get a list of all commandlets
Get-Command -CommandType Cmdlet | 
Out-GridView -PassThru -Title 'Available cmdlets'

# Get a list of all functions for the specified name
Get-Command -Name '*ADGroup*' -CommandType Function | 
Out-GridView -PassThru -Title 'Available named functions'

# Get a list of all commandlets for the specified name
Get-Command -Name '*ADGroup**'  -CommandType Cmdlet | 
Out-GridView -PassThru -Title 'Available named cmdlet'

# get function / cmdlet details
Get-Command -Name Get-ADUser -Syntax
(Get-Command -Name Get-ADUser).Parameters.Keys
Get-help -Name Get-ADUser -Full
Get-help -Name Get-ADUser -Online
Get-help -Name Get-ADUser -Examples

# Get parameter that accepts pipeline input
Get-Help Get-ADUser -Parameter * | 
Where-Object {$_.pipelineInput -match 'true'} | 
Select * 

# List of all parameters that a given cmdlet supports along with a short description:
Get-Help dir -para * | 
Format-Table Name, { $_.Description[0].Text } -wrap


# Find all cmdlets / functions with a target parameter
Get-Command -CommandType Function | 
Where-Object { $_.parameters.keys -match 'credential'} | 
Out-GridView -PassThru -Title 'Available functions which has a specific parameter'

Get-Command -CommandType Cmdlet | 
Where-Object { $_.parameters.keys -match 'credential'} | 
Out-GridView -PassThru -Title 'Results for cmdlets which has a specific parameter'

# Get named aliases 
Get-Alias | 
Out-GridView -PassThru -Title 'Available aliases'

# Get cmdlet / function parameter aliases
(Get-Command Get-ADUser).Parameters.Values | 
where aliases | 
select Name, Aliases | 
Out-GridView -PassThru -Title 'Alias results for a given cmdlet or function.'

### Query Powershell Data Types
[AppDomain]::CurrentDomain.GetAssemblies() | 
Foreach-Object { $_.GetExportedTypes() }

# Or 

[psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::get

# Or

[psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::Get.GetEnumerator() `
| Sort-Object -Property Key

<#
 Get any .NET types and their static methods from PowerShell. 
 Enumerate all that are currently loaded into your AppDomain.
#>  
[AppDomain]::CurrentDomain.GetAssemblies() | 
foreach { $_.GetTypes() } | 
foreach { $_.GetMethods() } | 
where { $_.IsStatic } | 
select DeclaringType, Name | 
Out-GridView -PassThru -Title '.NET types and their static methods'

正如已经指出的,有些东西(不一定总是模块/cmdlet)仅是 ISE(当然,这是 ISE 模块中的任何东西或类似的东西),这取决于您在做什么/正在做什么,例如很多形式的东西,但是只要您将适当的表单类/类型添加到您的代码中,它们就应该也能在控制台主机中正常运行.

As already noted, there are things (not necessarily modules / cmdlets always) that are ISE only (that's anything in the ISE module or the like of course) depending on what you are after / doing, such as lots form stuff, but as long as you add the appropriate form classes / types to your code, they should run just fine in the consolehost as well.

然而,认为标记为 ISE 的任何东西都可以在其他任何地方运行的想法是不正确的.还有很多 ISE 插件.您可以通过 ISE 附加组件菜单访问它们.在控制台主机中永远不应该期望该菜单中的任何内容.例如,这是一个内置工具,可直接在 ISE 编辑器选项卡 psEdit 中打开基于文本的文件.

Yet, it is not correct to think that anything that is marked as ISE would ever run anywhere else. There are lots of ISE addons as well. You can get to them via the ISE Add-Ons menu. Anything in that menu should never be expected in the consolehost. For example, that is a built in tool to open a text-based files in an ISE editor tab directly, psEdit.

Get-Help -Name psedit

NAME
    psEdit

SYNTAX
    psEdit [-filenames] <Object>  [<CommonParameters>]


ALIASES
    None


REMARKS
    None

尝试在控制台主机中使用它会失败,因为控制台主机没有这样的编辑器.

Trying to use that in the console host will fail, since the console host does not have such an editor.

您也可以在 ISE 中以编程方式进行操作,当然这种操作在控制台主机中是行不通的.

You can programmatically do things in the ISE as well, and of course this sort of thing would never work in the consolehost.

在此处查看详细信息:ISE 对象模型层次结构

要确保东西在您需要时就在应有的位置,请调整您的 PowerShell 配置文件.例如,这里是我在 ISE 与控制台主机中时要处理的示例.

To make sure stuff is where it should be when you need it, adjust you PowerShell profiles. For example here is a sample of what mine has in it to deal with when I am in the ISE vs the consolehost.

# Validate if in the ISE or not

If ($Host.Name -match 'ISE')
{
    Import-Module -Name PsISEProjectExplorer
    Import-Module -Name PSharp
    Import-Module -Name ClassExplorer

}

If ($Host.Name -notmatch 'ISE')
{ Import-Module -Name PSReadline }

Import-Module -Name PSScriptAnalyzer
Import-Module -Name Posh-SSH
Import-Module -Name ModuleLibrary -DisableNameChecking
Import-Module -Name Pester
Import-Module -Name PSKoans


If ($Host.Name -match 'ISE')
{
    #Script Browser Begin
    #Version: 1.3.2
    Add-Type -Path 'C:\Program Files (x86)\Microsoft Corporation\Microsoft Script Browser\System.Windows.Interactivity.dll'
    Add-Type -Path 'C:\Program Files (x86)\Microsoft Corporation\Microsoft Script Browser\ScriptBrowser.dll'
    Add-Type -Path 'C:\Program Files (x86)\Microsoft Corporation\Microsoft Script Browser\BestPractices.dll'
    $scriptBrowser = $psISE.CurrentPowerShellTab.VerticalAddOnTools.Add('Script Browser', [ScriptExplorer.Views.MainView], $true)
    $scriptAnalyzer = $psISE.CurrentPowerShellTab.VerticalAddOnTools.Add('Script Analyzer', [BestPractices.Views.BestPracticesView], $true)
    $psISE.CurrentPowerShellTab.VisibleVerticalAddOnTools.SelectedAddOnTool = $scriptBrowser
    #Script Browser End

    Set-StrictMode  -Version Latest 
}

OP 更新

至于……

那么,有没有办法查询实际加载的命令和是否可以在 powershell.exe(或 pwsh.exe)控制台中运行?

So, is there a way to query commands which are actually loaded and runnable in the powershell.exe (or pwsh.exe) console?

不是我认为你在想的那种感觉.您似乎对启动时加载了哪些 cmdlet 有所了解.那不是一回事.cmdlet 通过模块加载和路径公开.您期望 PowerShell 仅根据您所在的 PowerShell 版本/环境显示模块/cmdlet/函数.这也不是问题.PowerShell 将可以访问系统上的所有 .Net 以及定义路径中的任何内容.无论您是否加载和使用它们,都是另一回事.

Not in the sense I take you are thinking. You seem to have a concept of what cmdlets are loaded on startup. That's not a thing. cmdlets are exposed by module loading, and paths. What you are expecting is for PowerShell to only display modules / cmdlets / functions based on what PowerShell version / environment you are in. That is not a thing either. PowerShell will have access to all of .Net on your system and anything in the defined paths. Whether you load and use them or not, is a different matter.

Get-Module                # will show you all currently loaded ones.
Get-Module -ListAvailable # Will show all modules installed on your system.

如果您使用的是 PSv3 及更高版本,那么您的系统环境和 PowerShell 路径始终可用,因为您在路径中调用的任何内容都会在您尝试使用时自动加载.

If you are on PSv3 and higher, anything is your system environment and PowerShell paths are always available, as anything you call in the path would be auto-loaded when you try and use it.

再次 Get-Command 将列出所有可用的,它们仅在您调用一个时加载,并且在调用或会话完成/关闭时消失.

Again Get-Command will list all available, they are only loaded when you call one, and gone when the call or session is done / closed of course.

如果您的模块、cmdlet/函数不在预期(环境或 PS 路径)位置,则您必须添加该路径或使用它们的 UNC 路径来运行它们.因此,路径中的任何内容(来自任何 UNC 的点源)始终可用.如果您在 ISE 中,则可以在命令"选项卡中或使用 Get-Command 在控制台中看到此信息.

If you have modules, cmdlets / functions not in the expected (environment or PS paths) places, then you either have to add that path or use the use the UNC path to them to run them. So, anything in the paths, dot-sourced from any UNC, are always available. If you are in the ISE, you can see this in the Commands tab, or in the console by using Get-Command.

您可以即时或使用 PowerShell 配置文件临时添加路径,也可以通过 PowerShell 配置文件或使用 Windows 环境变量对话框永久添加路径.

You can add paths temporarily on the fly or using your PowerShell profiles or permanently on the fly, via your PowerShell profile, or using the Windows Environment variable dialog.

控制台主机和 ISE 将始终列出预期路径中的任何模块、cmdlet 和函数.它们并不意味着都可用.如前所述,由于显而易见的原因,ISe 特定模块、cmdlet、函数只能在 ISE 中工作.但是,ISE 将运行控制台主机将运行的任何模块 cmdlet ,除了 PSReadline.它会加载它,但它不会在 ISE 控制台中执行任何操作.ISE 控制台实际上是一个输出窗口,与控制台主机不同.好吧,您可以在其中执行 consolehost 之类的操作,但这不是一回事.

The consolehost and the ISE will always list any module, cmdlet, function in the expected paths. They does not mean that are all usable. As noted the ISe specific modules, cmdlets, functions will only work in the ISE for obvious reasons. Yet, the ISE will run any module, cmdlet , function the console host will, except for PSReadline. Well it will load it, but it won't do anything in the ISE console. The ISE console is really an output windows not a the same thing as the consolehost. Well, you can do consolehost like stuff in it, but it's not the same thing.

因此,模块被加载,模块公开其中的 cmdlet/函数.并非所有模块都默认加载,因此上面两个命令的原因,这就是导入模块和调用时自动加载的原因.独立的个人模块/cmdlet/函数/脚本不是 PS 知道的,除非你告诉它应该从哪里导入/加载/使用它们.

So, modules are loaded, modules expose the cmdlets / functions in them. Not all modules are loaded by default, hence the reason for the two command above, this is why Import-Module and auto load on call, exists. Standalone personal module / cmdlets / functions / scripts are not something PS will know about until you tell it where they should be imported / loaded / used from.

如果您真的对这类事情感到好奇,可以利用 Trace-Command cmdlet ...

If you are really curious about this sort of thing you can leverage the Trace-Command cmdlet ...

跟踪-命令

$A = "i*"
Trace-Command ParameterBinding {Get-Alias $Input} -PSHost -InputObject $A

DEBUG: ParameterBinding Information: 0 : BIND NAMED cmd line args [Get-Alias]
DEBUG: ParameterBinding Information: 0 : BIND POSITIONAL cmd line args [Get-Alias]
DEBUG: ParameterBinding Information: 0 :     BIND arg [System.Object[]] to parameter [Name]
DEBUG: ParameterBinding Information: 0 :         Binding collection parameter Name: argument type [Object[]], parameter type [System.String[]], collection type 
Array, element type [System.String], no coerceElementType
DEBUG: ParameterBinding Information: 0 :         Arg is IList with 1 elements
DEBUG: ParameterBinding Information: 0 :         Creating array with element type [System.String] and 1 elements
DEBUG: ParameterBinding Information: 0 :         Argument type System.Object[] is IList
DEBUG: ParameterBinding Information: 0 :         Adding element of type String to array position 0
DEBUG: ParameterBinding Information: 0 :         BIND arg [System.String[]] to param [Name] SUCCESSFUL
DEBUG: ParameterBinding Information: 0 : MANDATORY PARAMETER CHECK on cmdlet [Get-Alias]
DEBUG: ParameterBinding Information: 0 : CALLING BeginProcessing
DEBUG: ParameterBinding Information: 0 : CALLING EndProcessing

... 使用您的代码查看实际调用的内容,您将看到每次运行代码时都会调用它.

... with your code to see what is actually being called and you will see that it is called each time you run the code.

您安装的模块越多,摩尔纹 cmdlet/功能就会变得可用.如果你真的想一想,他们有数百个模块,因此有数千个暴露的 cmdlet/函数.为什么要在内存中加载所有内容.您的系统只会由于资源耗尽而失败.所以,只加载你真正需要的东西,PowerShell 只会在需要的时候调用它.如果您打算使用控制台主机或使用 ISE/VSCode 并仅在需要时使用控制台主机,请了解 ISE 特定的内容并忽略所有这些内容.这就是我做事的方式.我很少,如果需要去控制台主机做任何事情.ISE 是我的默认设置,VSCode 是我的次要(目前).有些人会对 ISE 大便,我不是其中之一.

The more modules you install, the moire cmdlets / functions become available. If you really think about this for a moment, their are hundreds of modules out their, and thus thousands of exposed cmdlets / functions. Why would you want all that loaded in memory. Your system would just fail due to resource exhaustion. So, only load what you really need, PowerShell will only call what it needs when it needs it. Know what is ISE specific and ignore all of that if you intend to live in the console host, or live in the ISE / VSCode, and shell out to the consolehost only when needed. This is how I do things. I rarely, if ever need to go to the console host for anything. ISE is my default, VSCode is my secondary (for now). There are those who poo-poo the ISE, I am not one of those types.

OP 更新

至于...

我的用例不是坐在 PC 前的用户,而是 NodeJS 应用程序它运行 powershell.exe (PS5) 或 pwsh.exe (PS6/Core) 主机.一世完全明白模块可能可用"但未加载,那就是我想查询的是:加载了哪些 cmdlet/函数(即无需加载模块即可立即运行).我找到它了Get-Command * 会列出 Cmdlet X 但会列出 Get-Command X 的奇怪/错误会废话的.我如何查询命令:你是否加载了可运行的?PS:谷歌powowshell"以查看我的项目.

My use case is not a user sitting at a PC but a NodeJS application which runs the powershell.exe (PS5) or pwsh.exe (PS6/Core) host. I totally get that modules may be "available" but not loaded and that's what I want to query: which cmdlets/functions are loaded (i.e. available to be run now without loading a module). I find it weird/buggy that Get-Command * will list Cmdlet X but Get-Command X wil crap out. How do I query a command: are you loaded runnable? PS: Google "powowshell" to see my project.

将链接放到您的项目而不是让我搜索它会有所帮助.8-} 并且它仅在 Google 中显示而不在其他引擎(如 DuckDuckGo 或 Bing)中显示这一事实有点奇怪,但是很好.

It would have helped just to put the link to your project vs making me search for it. 8-} and the fact that it only shows in in Google and not other engine like DuckDuckGo or Bing is a bit odd, but oh well.

所以,你的意思是这个集合 ---

So, you mean this collection ---

http://cawoodm.blogspot.comhttps://github.com/cawoodm/powowshell.

我去看看.但是,对于您所追求的,不要单独使用 Get-Command.将 Get-Module 与 Get-Command 结合使用以列出那些加载的模块中的 cmdlet/函数,以更接近您所追求的目标.通过这种方式,只会列出该会话的加载模块和关联的 cmdlet/函数.

I'll take a look. Yet, for what you are after, don't use Get-Command by itself. Use Get-Module in concert with Get-Command to list the cmdlets / functions from those loaded modules, to get closer to what you are after. By doing it this way, only the loaded modules and the associated cmdlets / functions for that session are listed.

# List all loaded session modules and the exposed cmdlets / functions in them
Get-Module -Name '*' | 
ForEach-Object { Get-Command -Module $PSItem }

# Results

 # List all loaded modules and the exposed cmdlets / functions in them
Get-Module -Name '*' | 
ForEach-Object { Get-Command -Module $PSItem }

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
... 
Cmdlet          Export-BinaryMiLog                                 1.0.0.0    CimCmdlets
Cmdlet          Get-CimAssociatedInstance                          1.0.0.0    CimCmdlets
Cmdlet          Get-CimClass                                       1.0.0.0    CimCmdlets
...
Cmdlet          Find-Member                                        1.1.0      ClassExplorer
Cmdlet          Find-Namespace                                     1.1.0      ClassExplorer
Cmdlet          Find-Type                                          1.1.0      ClassExplorer
...
Function        Get-IseSnippet                                     1.0.0.0    ISE
Function        Import-IseSnippet                                  1.0.0.0    ISE
Function        New-IseSnippet                                     1.0.0.0    ISE
Cmdlet          Add-Computer                                       3.1.0.0    Microsoft.PowerShell.Management
Cmdlet          Add-Content                                        3.1.0.0    Microsoft.PowerShell.Management
Cmdlet          Checkpoint-Computer                                3.1.0.0    Microsoft.PowerShell.Management                                   
...

OP 更新

至于...

您的解决方案将无法列出 cmdlet/函数(例如 ForEach-Object或 Stop-Job)没有模块关联(在我的系统上为 64).还,您如何确定 Get-Module 仅返回已加载的模块?

Your solution wil fail to list cmdlets/functions (e.g. ForEach-Object or Stop-Job) which have no module association (64 on my system). Also, how sure are you Get-Module returns only loaded modules?

PowerShell 从 PowerShell 源和模块中获取 cmdlet 和函数.

PowerShell gets cmdlets and functions from PowerShell sources and Modules.

如果您对指向的 cmdlet/函数进行查找,您将看到它们来自 这里:

If you do a lookup on the cmdlets / functions you are pointing to, you will see where they come from here:

'ForEach-Object','Start-Job' | 
    ForEach{
                Get-Command -CommandType Cmdlet -Name $PSItem | 
                Format-Table -AutoSize
           }

<#
CommandType Name           Version Source                   
----------- ----           ------- ------                   
Cmdlet      ForEach-Object 3.0.0.0 Microsoft.PowerShell.Core



CommandType Name      Version Source                   
----------- ----      ------- ------                   
Cmdlet      Start-Job 3.0.0.0 Microsoft.PowerShell.Core
#>

因此,基本 cmdlet/函数不是来自导入模块的工作.在 OS/.Net 安装中有设计.

So, the base cmdlets / functions are not from an Import-Module effort. There are just there by design in the OS/.Net install.

所以,我的解决方案并没有失败,我从来没有说过使用它会让你 100%. 这是一种向你展示模块加载的方式使用什么 cmdlet/函数,这与 Microsoft.PowerShell.Core、.Net 和/或操作系统版本允许的内容几乎没有任何关系(众所周知,Cmdlets/Functions/Modules 也是 OS 和 $PSVersion 特定的).

So, my solution is not a fail and I never said it would get you 100% by using that. It was a way of showing you what modules load for use what cmdlets / functions and that has little to nothing to do with what Microsoft.PowerShell.Core, .Net holistically and/or what the OS version allows (Cmdlets/Functions/Modules are also OS and $PSVersion specific as we all know).

同样,您尝试设计的用例是无效的.无论来源如何,Cmdlet 和函数都不会加载并可供使用.当您需要通过上述方式调用它们时,它们已安装或公开并可供使用.在您调用它们之前,它们永远不会被加载(位于内存中),GAC 中的任何东西都不会.

So, again, your use case for what you are trying to devise is not valid. Cmdlets and functions, regardless of source are not loaded and ready for use. They are installed or exposed and available for use when you need to call them via the aforementioned. They are not ever loaded (sitting in memory) until you call them, no more that anything in the GAC is.

所以,看着您的项目,我明白您正在尝试做什么,但您正在尝试为用户着想.正如您作为开发人员必须从 GAC 中引用一个程序集(其中有成千上万的内容,但在您引用它们之前不会加载),您必须知道它在哪里以及您想使用哪个,以及为什么.因此,对于 PowerShell 可以访问的内容,采用相同的思维方式.请注意,我说的是访问权限,而不是您是否可以在 PowerShell 会话中使用它.

So, looking at you project, I see what you are trying to do, but you are trying to think for the user. Just as you as a developer have to reference an assembly from the GAC (which has thousands of things that are there, but are not loaded until you reference them), and you have to know where it is and which one you want to use and why. So, goes the same mindset for what PowerShell can have access to. Note, I said access to, not whether you can use it or not in a PowerShell session.

所以,如果我们涉足这个领域,我们会得到...

So, if we step into this, we get...

Cmdlets / Function come from. The OS (DLLs), [.Net][4], [Core module][3], and those exported from the modules you Import.

所以,再次,您认为必须是,在导入模块或 DLL 时什么是可用的或可用的.导入的模块及其关联的 cmdlet/函数可能无法工作,具体取决于您所在的会话类型.意思是,ISE 与控制台主机.

So, again, you thought has to be, what is available, or made available when modules or DLLs are imported. Imported modules and their associated cmdlets / function may not work, depending on what type of session you in. Meaning, ISE vs consolhost.

仅供参考,你必须扩大你的视野......

FYI, you have to widen you view of this...

在 ISE

# Total host available commands cmdlet / Functions regadless where the come from
(Get-Command).Count
8750
# Total host avaialble cmdlets
(Get-Command -CommandType Cmdlet).Count
4772
# Total host available functions
(Get-Command -CommandType Function).Count
3035

# Difference of host available cmdlets / functions not shown that are part of the previous two calls.
(Get-Command).Count - ((Get-Command -CommandType Cmdlet).Count + (Get-Command -CommandType Function).Count)
943

# Further breakdown
(Get-Command -CommandType Alias).Count
1446
(Get-Command -CommandType Application).Count
937
(Get-Command -CommandType Configuration).Count
# The property 'Count' cannot be found on this object. Verify that the property exists.
(Get-Command -CommandType ExternalScript).Count
2
(Get-Command -CommandType Script).Count
# The property 'Count' cannot be found on this object. Verify that the property exists.
(Get-Command -CommandType Filter).Count
2
(Get-Command -CommandType Workflow).Count
# The property 'Count' cannot be found on this object. Verify that the property exists.
(Get-Command -CommandType All).Count
10219


# Get a list of all Modules
(Get-Module -ListAvailable).Count
387

# Get a list of all loaded Modules
(Get-Module).Count
12

# List all loaded session modules and the exposed cmdlets / functions in them
(Get-Module -Name '*' | 
ForEach-Object { Get-Command -Module $PSItem }).Count
505

(Get-Module -ListAvailable | 
ForEach {
    Get-Module -Name $PSItem.Name | 
    ForEach-Object { Get-Command -Module $PSItem }
}).Count
669



# If I Import another 3rdP module I installed from the gallery, things will change of course

Import-Module -Name ShowUI

# Get a list of all Modules
(Get-Module -ListAvailable).Count
387

# Get a list of all loaded Modules
(Get-Module).Count
13

# List all loaded session modules and the exposed cmdlets / functions in them
(Get-Module -Name '*' | 
ForEach-Object { Get-Command -Module $PSItem }).Count
937

(Get-Module -ListAvailable | 
ForEach {
    Get-Module -Name $PSItem.Name | 
    ForEach-Object { Get-Command -Module $PSItem }
}).Count
1101

在控制台主机中 - 注意差异

# Total host available commands cmdlet / Functions regadless where the come from
(Get-Command).Count
9191

# Total host avaialble cmdlets
(Get-Command -CommandType Cmdlet).Count
4772

# Total host available functions
(Get-Command -CommandType Function).Count
3472

# Difference of host available cmdlets / functions not shown that are part of the previous two calls.
(Get-Command).Count - ((Get-Command -CommandType Cmdlet).Count + (Get-Command -CommandType Function).Count)
947


# Further breakdown
(Get-Command -CommandType Alias).Count
1809

(Get-Command -CommandType Application).Count
937

(Get-Command -CommandType Configuration).Count
0
# The property 'Count' cannot be found on this object. Verify that the property exists.
(Get-Command -CommandType ExternalScript).Count
2

(Get-Command -CommandType Script).Count
0
# The property 'Count' cannot be found on this object. Verify that the property exists.
(Get-Command -CommandType Filter).Count
1

(Get-Command -CommandType Workflow).Count
1
# The property 'Count' cannot be found on this object. Verify that the property exists.
(Get-Command -CommandType All).Count
10994




# Get a list of all Modules
(Get-Module -ListAvailable).Count
387

# Get a list of all loaded Modules
(Get-Module).Count
8

# List all loaded session modules and the exposed cmdlets / functions in them
(Get-Module -Name '*' | 
ForEach-Object { Get-Command -Module $PSItem }).Count
467

(Get-Module -ListAvailable | 
ForEach {
    Get-Module -Name $PSItem.Name | 
    ForEach-Object { Get-Command -Module $PSItem }
}).Count
623



# If I Import another 3rdP module I installed from the gallery, things will change of course

Import-Module -Name ShowUI

# Get a list of all Modules
(Get-Module -ListAvailable).Count
387


# Get a list of all loaded Modules
(Get-Module).Count
9


# List all loaded session modules and the exposed cmdlets / functions in them
(Get-Module -Name '*' |
ForEach-Object { Get-Command -Module $PSItem }).Count
899


(Get-Module -ListAvailable |
ForEach {
    Get-Module -Name $PSItem.Name |
    ForEach-Object { Get-Command -Module $PSItem }
}).Count
1055

这篇关于如何在powershell中列出所有已安装、可运行的cmdlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆