当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 PowerShell 中查找包

作者:精品下载站 日期:2024-12-14 17:29:25 浏览:12 分类:玩电脑

在 PowerShell 中查找包


`Find-Package` 是 PowerShell PackageManagement 模块中的 cmdlet。它用于在可用存储库中查找软件包。这些存储库可以包括 PowerShell 库、Chocolatey、Nuget 等。

下面是一个用于在可用存储库中查找包的 PowerShell 命令。

Find-Package *

PowerShell PackageManagement 模块中的 Find-Package 命令可用于从软件包提供者查找所有可用的软件包、从软件包源查找软件包、查找某个软件包的所有版本package,并找到具有特定名称的包。

在本文中,我们将讨论如何使用 Powershell 中的 Find-Package cmdlet 在可用存储库中搜索包。

如何从软件包提供商处查找所有可用的软件包

要从软件包提供程序查找所有可用软件包,请使用带有 -ProviderName 参数的 Find-Package 命令。

Find-Package -ProviderName PowerShellGet

在上面的 PowerShell 脚本中,Find-Package 命令使用 ProviderName 参数指定提供程序 PowerShellGet 并查找以下位置中所有可用的 PowerShell 模块包:已注册的 PSGallery

下面给出了上述列出所有包的 PowerShell 脚本的输出。

[玩转系统] 在 PowerShell 中查找包

如何从包源查找包

使用 Find-Package 命令和 Source 参数从指定的包源中查找包。

Find-Package -Name Az.Postgresql  -Source PSGallery  

在上面的 PowerShell 脚本中,Find-Package 命令使用 Name 参数指定包名称“Az.Postgresql”和 Source 参数指定包源“PSGallery”。此命令从指定的包源查找最新版本的包。

下面给出了上述从包源搜索包名称的 PowerShell 脚本的输出。

PS C:\> Find-Package -Name Az.Postgresql  -Source PSGallery    
                                                                                   
Name                           Version          Source           Summary
----                           -------          ------           -------
Az.PostgreSql                  1.1.0            PSGallery        Microsoft Azure PowerShell: PostgreSql cmdlets


PS C:\>                                                                                                                                                      

如何查找软件包的所有版本

要查找包的所有版本,请使用带参数 AllVersionsFind-Package 命令。

Find-Package -Name Az.Postgresql  -Source PSGallery -AllVersions

在上面的 PowerShell 脚本中,Find-Package cmdlet 使用 Name 参数指定包名称“Az.Postgresql”和 Source“ PSGallery”。然后,它使用 AllVersions 参数来检索包的所有可用版本。

上述 PowerShell 脚本的输出查找指定提供商的所有可用软件包版本,如下所示。

PS C:\> Find-Package -Name Az.Postgresql  -Source PSGallery -AllVersions                                                                          
Name                           Version          Source           Summary
----                           -------          ------           -------
Az.PostgreSql                  1.1.0            PSGallery        Microsoft Azure PowerShell: PostgreSql cmdlets
Az.PostgreSql                  1.0.0            PSGallery        Microsoft Azure PowerShell: PostgreSql cmdlets
Az.PostgreSql                  0.8.0            PSGallery        Microsoft Azure PowerShell: PostgreSql cmdlets
Az.PostgreSql                  0.7.0            PSGallery        Microsoft Azure PowerShell: PostgreSql cmdlets
Az.PostgreSql                  0.6.0            PSGallery        Microsoft Azure PowerShell: PostgreSql cmdlets
Az.PostgreSql                  0.5.0            PSGallery        Microsoft Azure PowerShell: PostgreSql cmdlets
Az.PostgreSql                  0.4.0            PSGallery        Microsoft Azure PowerShell: PostgreSql cmdlets
Az.PostgreSql                  0.3.0            PSGallery        Microsoft Azure PowerShell: PostgreSql cmdlets
Az.PostgreSql                  0.2.0            PSGallery        Microsoft Azure PowerShell: PostgreSql cmdlets
Az.PostgreSql                  0.1.0            PSGallery        Microsoft Azure PowerShell: PostgreSql cmdlets


PS C:\>     

如何查找具有特定名称的包

您可以在 PowerShell 中使用 Find-Package 命令从指定提供商查找具有特定名称的包。

Find-Package -Name PackageManagement -ProviderName PowerShellGet -RequiredVersion 1.3.1   

在上面的 PowerShell 脚本中,Find-Package 命令使用 Name 参数指定包名称“PackageManagement”。 ProviderName 参数指定在“PowerShellGet”中搜索包。 RequiredVersion 指定仅检查版本 1.3.1 并返回结果。

上述 PowerShell 脚本的输出从指定的提供程序中查找特定的软件包版本。

PS C:\> Find-Package -Name PackageManagement -ProviderName PowerShellGet -RequiredVersion 1.3.1    
                                               
Name                           Version          Source           Summary
----                           -------          ------           -------
PackageManagement              1.3.1            PSGallery        PackageManagement (a.k.a. OneGet) is a new way to discover and install softwa...


PS C:\>      

结论

希望上面关于如何使用PowerShell模块中的Find-Package命令在提供程序中搜索包的文章对您有所帮助。

您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。

相关链接

获取包

获取PackageProvider

安装包

安装 NuGet 包

获取包源

注册包源

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯