Find-Module

查找与指定条件匹配的存储库中的模块。

语法

Find-Module
    [[-Name] <string[]>]
    [-MinimumVersion <string>]
    [-MaximumVersion <string>]
    [-RequiredVersion <string>]
    [-AllVersions]
    [-IncludeDependencies]
    [-Filter <string>]
    [-Tag <string[]>]
    [-Includes <string[]>]
    [-DscResource <string[]>]
    [-RoleCapability <string[]>]
    [-Command <string[]>]
    [-Proxy <uri>]
    [-ProxyCredential <pscredential>]
    [-Repository <string[]>]
    [-Credential <pscredential>]
    [-AllowPrerelease]
    [<CommonParameters>]

说明

Find-Module cmdlet 查找与指定条件匹配的存储库中的模块。 Find-Module 为找到的每个模块返回 PSRepositoryItemInfo 对象。 可以将对象向下发送到 cmdlet,例如 Install-Module

首次 Find-Module 尝试使用存储库时,系统可能会提示你安装更新。 如果未向 Register-PSRepository cmdlet 注册存储库源,则返回错误。

Find-Module 如果未使用任何参数来限制版本,则返回模块的最新版本。 若要获取模块版本的存储库列表,请使用参数 AllVersions

如果指定 MinimumVersion 参数, Find-Module 则返回等于或大于最小值的模块版本。 如果存储库中提供了较新版本,则会返回较新版本。

如果指定 了 MaximumVersion 参数, Find-Module 则返回未超过指定版本的模块的最新版本。

如果指定 RequiredVersion 参数, Find-Module 则仅返回与指定版本完全匹配的模块版本。 Find-Module 搜索所有可用模块,因为源之间可能发生名称冲突。

采用模块版本号的参数需要格式化为版本号的字符串。

  • 标准版本号的格式为 x.y.z x、y 和 z 是数字
  • 预发行版版本的格式是x.y.z-<prerelease_label><prerelease_label>分配给该版本的任意字符串。

以下示例使用 PowerShell 库 作为唯一注册的存储库。 Get-PSRepository 显示已注册的存储库。 如果有多个已注册的存储库,请使用 -Repository 参数指定存储库的名称。

示例

示例 1:按名称查找模块

此示例在默认存储库中找到一个模块。

Find-Module -Name PowerShellGet

Version   Name              Repository           Description
-------   ----              ----------           -----------
2.1.0     PowerShellGet     PSGallery            PowerShell module with commands for discovering...

Find-Module cmdlet 使用 Name 参数指定 PowerShellGet 模块。

示例 2:查找具有类似名称的模块

此示例使用星号 (*) 通配符查找具有类似名称的模块。

Find-Module -Name PowerShell*

Version   Name                            Repository    Description
-------   ----                            ----------    -----------
0.4.0     powershell-yaml                 PSGallery     Powershell module for serializing and...
2.1.0     PowerShellGet                   PSGallery     PowerShell module with commands for...
1.9       Powershell.Helper.Extension     PSGallery     # Powershell.Helper.Extension...
3.1       PowerShellHumanizer             PSGallery     PowerShell Humanizer wraps Humanizer...
4.0       PowerShellISEModule             PSGallery     a module that adds capability to the ISE

Find-Module cmdlet 使用 Name 参数和星号 (*) 通配符查找包含 PowerShell 的所有模块。

示例 3:按最低版本查找模块

此示例搜索模块的最低版本。 如果存储库包含较新版本的模块,则返回较新版本。

Find-Module -Name PowerShellGet -MinimumVersion 1.6.5

Version   Name             Repository     Description
-------   ----             ----------     -----------
2.1.0     PowerShellGet    PSGallery      PowerShell module with commands for discovering...

Find-Module cmdlet 使用 Name 参数指定 PowerShellGet 模块。 MinimumVersion 指定版本 1.6.5Find-Module 返回 PowerShellGet 版本 2.1.0 ,因为它超出了最低版本,并且是最新版本。

示例 4:按特定版本查找模块

此示例演示如何安装模块的特定预发行版。 预发行版本的格式为 <version_number>-<prerelease_label>.

Find-Module PSReadLine -AllowPrerelease -RequiredVersion 2.2.4-beta1

Version        Name             Repository       Description
-------        ----             ----------       -----------
2.2.4-beta1    PSReadLine       PSGallery        Great command line editing in the PowerS…

示例 5:在特定存储库中查找模块

此示例使用 Repository 参数查找特定存储库中的模块。

Find-Module -Name PowerShellGet -Repository PSGallery

Version   Name             Repository     Description
-------   ----             ----------     -----------
2.1.0     PowerShellGet    PSGallery      PowerShell module with commands for discovering...

Find-Module cmdlet 使用 Name 参数指定 PowerShellGet 模块。 Repository 参数指定搜索 PSGallery 存储库。

示例 6:在多个存储库中查找模块

此示例使用指定 Register-PSRepository 存储库。 Find-Module 使用存储库搜索模块。

Register-PSRepository -Name MySource -SourceLocation https://www.myget.org/F/powershellgetdemo/
Find-Module -Name Contoso* -Repository PSGallery, MySource

Repository    Version   Name             Description
----------    -------   ----             -----------
PSGallery     2.0.0.0   ContosoServer    Cmdlets and DSC resources for managing Contoso Server...
MySource      1.2.0.0   ContosoClient    Cmdlets and DSC resources for managing Contoso Client...

Register-PSRepository cmdlet 注册新的存储库。 Name 参数分配名称 MySourceSourceLocation 参数指定存储库的地址。

cmdlet Find-Module 使用 星号 (*) 通配符的 Name 参数来指定 Contoso 模块。 Repository 参数指定搜索两个存储库:PSGalleryMySource

示例 7:查找包含 DSC 资源的模块

此命令返回包含 DSC 资源的模块。 Includes 参数具有四个预定义的功能,用于搜索存储库。 使用 Tab-complete 显示 Includes 参数支持的四个功能。

Find-Module -Repository PSGallery -Includes DscResource

Version     Name                            Repository    Description
-------     ----                            ----------    -----------
2.7.0       Carbon                          PSGallery     Carbon is a PowerShell module...
8.5.0.0     xPSDesiredStateConfiguration    PSGallery     The xPSDesiredStateConfiguration module...
1.3.1       PackageManagement               PSGallery     PackageManagement (a.k.a. OneGet) is...
2.7.0.0     xWindowsUpdate                  PSGallery     Module with DSC Resources...
3.2.0.0     xCertificate                    PSGallery     This module includes DSC resources...
3.1.0.0     xPowerShellExecutionPolicy      PSGallery     This DSC resource can change the user...

Find-Module cmdlet 使用 Repository 参数搜索存储库 PSGalleryIncludes 参数指定 DscResource,这是参数可以在存储库中搜索的功能。

示例 8:使用筛选器查找模块

在此示例中,若要查找模块,将使用筛选器来搜索存储库。

对于基于 NuGet 的存储库, Filter 参数通过参数的名称、说明和标记进行搜索。

Find-Module -Filter AppDomain

Version    Name              Repository           Description
-------    ----              ----------           -----------
1.0.0.0  AppDomainConfig     PSGallery            Manipulate AppDomain configuration...
1.1.0    ClassExplorer       PSGallery            Quickly search the AppDomain for classes...

Find-Module cmdlet 使用 Filter 参数搜索 AppDomain 的存储库。

示例 9:按标记查找模块

此示例演示如何按标记查找模块。 该值 CrescendoBuilt 是自动添加到使用 Microsoft.PowerShell.Crescendo 模块创建的模块的标记。

Find-Module -Tag CrescendoBuilt

Version Name            Repository Description
------- ----            ---------- -----------
0.1.0   Foil            PSGallery  A PowerShell Crescendo wrapper for Chocolatey
0.3.1   Cobalt          PSGallery  A PowerShell Crescendo wrapper for WinGet
1.1.0   SysInternals    PSGallery  PowerShell cmdlets for SysInternal tools
0.0.4   Croze           PSGallery  A PowerShell Crescendo wrapper for Homebrew
0.0.2   AptPackage      PSGallery  PowerShell Crescendo-generated Module to query APT-Package Information
1.0.1   RoboCopy        PSGallery  PowerShell cmdlet for the official RoboCopy.exe
1.0.2   TShark          PSGallery  PowerShell cmdlet for tshark.exe
1.0.0   SpeedTestCLI    PSGallery  PowerShell cmdlets speedtest-cli
1.0.0   SpeedTest-CLI   PSGallery  PowerShell cmdlets for Internet Speed Test
1.0.2   Image2Text      PSGallery  PowerShell Images into ASCII art
0.1.1   Quser.Crescendo PSGallery  This module displays session information of users logged onto a local or remote m...
1.0.2   Takeown         PSGallery  Crescendo Powershell wrapper of takeown.exe

参数

-AllowPrerelease

包括在标记为预发行的结果模块中。

类型:SwitchParameter
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-AllVersions

指定在结果中包含模块的所有版本。 不能将 AllVersions 参数与 MinimumVersionMaximumVersionRequiredVersion 参数一起使用。

类型:SwitchParameter
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Command

指定要在模块中找到的命令数组。 命令可以是函数或工作流。

类型:String[]
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Credential

指定有权为指定的包提供程序或源安装模块的用户帐户。

类型:PSCredential
Position:Named
默认值:None
必需:False
接受管道输入:True
接受通配符:False

-DscResource

指定包含 DSC 资源的模块的名称或部分名称。 根据 PowerShell 约定,在提供多个参数时执行 OR 搜索。

类型:String[]
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Filter

根据 PackageManagement 提供程序特定的搜索语法指定筛选器。 对于 NuGet 模块,此参数等效于使用 PowerShell 库 网站上的搜索栏进行搜索。

类型:String
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-IncludeDependencies

指示此作包括依赖于 Name 参数中指定的模块的所有模块。

类型:SwitchParameter
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Includes

仅返回包含特定类型的 PowerShell 功能的模块。 例如,你可能只想查找包含 DSCResource 的模块。 此参数的可接受值如下所示:

  • Cmdlet
  • DscResource
  • 功能
  • RoleCapability
类型:String[]
接受的值:DscResource, Cmdlet, Function, RoleCapability
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-MaximumVersion

指定要包含在搜索结果中的模块的最大版本或最新版本。 MaximumVersionRequiredVersion 不能在同一命令中使用。

类型:String
Position:Named
默认值:None
必需:False
接受管道输入:True
接受通配符:False

-MinimumVersion

指定要包含在结果中的模块的最低版本。 MinimumVersionRequiredVersion 不能在同一命令中使用。

类型:String
Position:Named
默认值:None
必需:False
接受管道输入:True
接受通配符:False

-Name

指定要在存储库中搜索的模块的名称。 接受以逗号分隔的模块名称列表。 可以使用通配符。

类型:String[]
Position:0
默认值:None
必需:False
接受管道输入:True
接受通配符:True

-Proxy

指定请求的代理服务器,而不是直接连接到 Internet 资源。

类型:Uri
Position:Named
默认值:None
必需:False
接受管道输入:True
接受通配符:False

-ProxyCredential

指定有权使用 Proxy 参数指定的代理服务器的用户帐户。

类型:PSCredential
Position:Named
默认值:None
必需:False
接受管道输入:True
接受通配符:False

-Repository

使用 Repository 参数指定要搜索模块的存储库。 注册多个存储库时使用。 接受以逗号分隔的存储库列表。 若要注册存储库,请使用 Register-PSRepository。 若要显示已注册的存储库,请使用 Get-PSRepository

类型:String[]
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-RequiredVersion

指定要包含在结果中的模块的确切版本号。 RequiredVersion 不能与 MinimumVersionMaximumVersion 相同的命令中使用。

类型:String
Position:Named
默认值:None
必需:False
接受管道输入:True
接受通配符:False

-RoleCapability

指定角色功能的数组。

类型:String[]
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Tag

指定一个标签数组。 示例标记包括 DesiredStateConfigurationDSCDSCResourceKitPSModule

类型:String[]
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

输入

String[]

String

Uri

PSCredential

输出

PSRepositoryItemInfo

Find-Module 创建可将管道发送到 cmdlet 的 PSRepositoryItemInfo 对象,例如 Install-Module

备注

PowerShell 包含以下与 Find-Module相关的别名:

  • 所有平台:
    • fimo

重要

截至 2020 年 4 月,PowerShell 库不再支持传输层安全性(TLS)版本 1.0 和 1.1。 如果未使用 TLS 1.2 或更高版本,则尝试访问 PowerShell 库时会收到错误。 使用以下命令确保使用的是 TLS 1.2:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

有关详细信息,请参阅 PowerShell 博客中的 公告