Find-Module
在存储库中查找符合指定条件的模块。
语法
Find-Module
[[-Name] <string[]>]
[-MinimumVersion <version>]
[-MaximumVersion <version>]
[-RequiredVersion <version>]
[-AllVersions]
[-IncludeDependencies]
[-Filter <string>]
[-Tag <string[]>]
[-Includes <string[]>]
[-DscResource <string[]>]
[-Command <string[]>]
[-Repository <string[]>]
[<CommonParameters>]
说明
cmdlet Find-Module
在存储库中查找与指定条件匹配的模块。
Find-Module
为其找到的每个模块返回 PSRepositoryItemInfo 对象。 可以将对象向下发送到 cmdlet,例如 Install-Module
。
首次尝试使用存储库时 Find-Module
,系统可能会提示你安装更新。
如果未向 cmdlet 注册 Register-PSRepository
存储库源,则返回错误。
Find-Module
如果未使用限制版本的参数,则返回模块的最新版本。 若要获取存储库的模块版本列表,请使用参数 AllVersions。
如果指定了 MinimumVersion 参数, Find-Module
则返回等于或大于最小值的模块版本。 如果存储库中有较新版本可用,则返回较新版本。
如果指定 了 MaximumVersion 参数, Find-Module
则返回不超过指定版本的模块的最新版本。
如果指定 了 RequiredVersion 参数, Find-Module
则仅返回与指定版本完全匹配的模块版本。 Find-Module
搜索所有可用模块,因为源之间可能发生名称冲突。
以下示例使用 PowerShell 库 作为唯一已注册的存储库。 Get-PSRepository
显示已注册的存储库。 如果有多个已注册的存储库,请使用 -Repository
参数指定存储库的名称。
示例
示例 1:按名称查找模块
此示例在默认存储库中查找模块。
Find-Module -Name PowerShellGet
Version Name Repository Description
------- ---- ---------- -----------
2.1.0 PowerShellGet PSGallery PowerShell module with commands for discovering...
cmdlet Find-Module
使用 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
cmdlet Find-Module
使用带有星号的 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...
cmdlet Find-Module
使用 Name 参数指定 PowerShellGet 模块。 MinimumVersion 指定版本 1.6.5。 Find-Module
返回 PowerShellGet 版本 2.1.0 ,因为它超出了最低版本,并且是最新版本。
示例 4:按特定版本查找模块
此示例返回一个 对象,该对象表示模块的特定版本。 如果未找到指定的版本,则返回错误。
Find-Module -Name PowerShellGet -RequiredVersion 1.6.5
Version Name Repository Description
------- ---- ---------- -----------
1.6.5 PowerShellGet PSGallery PowerShell module with commands for discovering...
cmdlet Find-Module
使用 Name 参数指定 PowerShellGet 模块。 RequiredVersion 参数指定版本 1.6.5。
示例 5:在特定存储库中查找模块
此示例使用 Repository 参数在特定存储库中查找模块。
Find-Module -Name PowerShellGet -Repository PSGallery
Version Name Repository Description
------- ---- ---------- -----------
2.1.0 PowerShellGet PSGallery PowerShell module with commands for discovering...
cmdlet Find-Module
使用 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...
cmdlet Register-PSRepository
注册新的存储库。 Name 参数分配名称 MySource。 SourceLocation 参数指定存储库的地址。
cmdlet Find-Module
使用带有星号的 Name 参数 (*
通配符) 指定 Contoso 模块。 Repository 参数指定搜索两个存储库:PSGallery 和 MySource。
示例 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...
cmdlet Find-Module
使用 Repository 参数搜索存储库 PSGallery。
Include 参数指定 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...
cmdlet Find-Module
使用 Filter 参数在存储库中搜索 AppDomain。
参数
-AllVersions
指定在结果中包含模块的所有版本。 不能将 AllVersions 参数与 MinimumVersion、 MaximumVersion 或 RequiredVersion 参数一起使用。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Command
指定要在模块中查找的命令数组。 命令可以是函数或工作流。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DscResource
指定包含 DSC 资源的模块的名称或名称的一部分。 根据 PowerShell 约定,在提供多个参数时执行 OR 搜索。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Filter
指定基于 PackageManagement 提供程序特定的搜索语法的筛选器。 对于 NuGet 模块,此参数等效于使用PowerShell 库网站上的搜索栏进行搜索。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-IncludeDependencies
指示此操作包括依赖于 Name 参数中指定的模块的所有模块。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Includes
仅返回包含特定 PowerShell 功能的模块。 例如,你可能只想查找包含 DSCResource 的模块。 此参数的可接受值如下所示:
- Cmdlet
- DscResource
- 函数
- RoleCapability
Type: | String[] |
Accepted values: | Cmdlet, DscResource, Function, RoleCapability |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-MaximumVersion
指定要包含在搜索结果中的模块的最高版本或最新版本。 不能 在同一命令中使用 MaximumVersion 和 RequiredVersion 。
Type: | Version |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-MinimumVersion
指定要包括在结果中的模块的最低版本。 MinimumVersion 和 RequiredVersion 不能在同一命令中使用。
Type: | Version |
Aliases: | Version |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Name
指定要在存储库中搜索的模块的名称。 接受以逗号分隔的模块名称列表。 可以使用通配符。
Type: | String[] |
Position: | 0 |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | True |
-Repository
使用 Repository 参数指定要搜索模块的存储库。 在注册多个存储库时使用。 接受以逗号分隔的存储库列表。 若要注册存储库,请使用 Register-PSRepository
。 若要显示已注册的存储库,请使用 Get-PSRepository
。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-RequiredVersion
指定要包含在结果中的模块的确切版本号。 RequiredVersion 不能与 MinimumVersion 或 MaximumVersion 在同一命令中使用。
Type: | Version |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Tag
指定标记的数组。 示例标记包括 DesiredStateConfiguration、 DSC、 DSCResourceKit 或 PSModule。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
输出
PSRepositoryItemInfo
Find-Module
创建 PSRepositoryItemInfo 对象,这些对象可在管道中向下发送到 cmdlet,例如 Install-Module
。
备注
此 cmdlet 在 PowerShell 5.0 或更高版本的 Windows PowerShell、Windows 7 或 Windows 2008 R2 及更高版本的 Windows 上运行。