Get-Package

Returns a list of all software packages that were installed with PackageManagement.

语法

NuGet

Get-Package
    [[-Name] <String[]>]
    [-RequiredVersion <String>]
    [-MinimumVersion <String>]
    [-MaximumVersion <String>]
    [-AllVersions]
    [-Force]
    [-ForceBootstrap]
    [-ProviderName <String[]>]
    [-Destination <String>]
    [-ExcludeVersion]
    [-Scope <String>]
    [-SkipDependencies]
    [<CommonParameters>]

PowerShellGet

Get-Package
    [[-Name] <String[]>]
    [-RequiredVersion <String>]
    [-MinimumVersion <String>]
    [-MaximumVersion <String>]
    [-AllVersions]
    [-Force]
    [-ForceBootstrap]
    [-ProviderName <String[]>]
    [-Scope <String>]
    [-PackageManagementProvider <String>]
    [-Type <String>]
    [-AllowClobber]
    [-SkipPublisherCheck]
    [-InstallUpdate]
    [-NoPathUpdate]
    [-AllowPrereleaseVersions]
    [<CommonParameters>]

说明

The Get-Package cmdlet returns a list of all software packages on the local computer that were installed with PackageManagement. You can run Get-Package on remote computers by running it as part of an Invoke-Command or Enter-PSSession command or script.

Important

The commands contained in the PackageManagement module are different than the commands provided by the NuGet module in the Package Manager Console of Visual Studio. Each module has commands that are not available in the other. Commands with the same name differ in their specific arguments. For more information, see the PowerShell reference documentation for the Package Manager Console of Visual Studio.

示例

Example 1: Get all installed packages

The Get-Package cmdlet gets all packages that are installed on the local computer.

Get-Package
Name           Version      Source                                     ProviderName
----           -------      ------                                     ------------
posh-git       0.7.3        https://www.powershellgallery.com/api/v2   PowerShellGet

Example 2: Get packages that are installed on a remote computer

This command gets a list of packages that were installed by PackageManagement on a remote computer. This command prompts you to provide the specified user's password.

PS> Invoke-Command -ComputerName Server01 -Credential CONTOSO\TestUser -ScriptBlock {Get-Package}

Invoke-Command uses the ComputerName parameter to specify a remote computer, Server01. The Credential parameter specifies a domain and user name with permissions to run commands on the computer. The ScriptBlock parameter runs the Get-Package cmdlet on the remote computer.

Example 3: Get packages for a specified provider

This command gets software packages installed on the local computer from a specific provider.

Get-Package -ProviderName PowerShellGet -AllVersions
Name                  Version      Source                                     ProviderName
----                  -------      ------                                     ------------
PackageManagement     1.2.2        https://www.powershellgallery.com/api/v2   PowerShellGet
PackageManagement     1.3.1        https://www.powershellgallery.com/api/v2   PowerShellGet
posh-git              0.7.3        https://www.powershellgallery.com/api/v2   PowerShellGet
PowerShellGet         2.0.1        https://www.powershellgallery.com/api/v2   PowerShellGet

Get-Package uses the ProviderName parameter to specify a specific provider, PowerShellGet. The AllVersions parameter displays each version that is installed.

Example 4: Get an exact version of a specific package

This command gets a specific version of an installed package. More than one version of a package can be installed.

Get-Package -Name PackageManagement -ProviderName PowerShellGet -RequiredVersion 1.3.1
Name                  Version      Source                                     ProviderName
----                  -------      ------                                     ------------
PackageManagement     1.3.1        https://www.powershellgallery.com/api/v2   PowerShellGet

Get-Package uses Name parameter to specify the package name, PackageManagement. The ProviderName parameter specifies the provider, PowerShellGet. The RequiredVersion parameter specifies an installed version.

Example 5: Uninstall a package

This example gets package information and then uninstalls the package.

Get-Package -Name posh-git -RequiredVersion 0.7.3 | Uninstall-Package

Get-Package uses the Name parameter to specify the package name, posh-git. The RequiredVersion parameter is a specific version of the package. The object is sent down the pipeline to the Uninstall-Package cmdlet. Uninstall-Package removes the package.

参数

-AllowClobber

Overrides warning messages about conflicts with existing commands. Overwrites existing commands that have the same name as commands being installed by a module.

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

PowerShellGet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-AllowPrereleaseVersions

Includes packages marked as a prerelease in the results.

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

PowerShellGet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-AllVersions

Indicates that Get-Package returns all available versions of the package. By default, Get-Package only returns the newest available version.

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Destination

Specifies the path to a directory that contains extracted package files.

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

NuGet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ExcludeVersion

Switch to exclude the version number in the folder path.

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

NuGet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Force

Forces the command to run without asking for user confirmation.

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ForceBootstrap

Indicates that Get-Package forces PackageManagement to automatically install the package provider.

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-InstallUpdate

Indicates that this cmdlet installs updates.

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

PowerShellGet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-MaximumVersion

Specifies the maximum package version that you want to find.

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-MinimumVersion

Specifies the minimum package version that you want to find. If a higher version is available, that version is returned.

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Name

Specifies one or more package names, or package names with wildcard characters. Separate multiple package names with commas.

参数属性

类型:

String[]

默认值:None
支持通配符:True
不显示:False

参数集

(All)
Position:0
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-NoPathUpdate

NoPathUpdate only applies to the Install-Script cmdlet. NoPathUpdate is a dynamic parameter added by the provider and isn't supported by Get-Package.

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

PowerShellGet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-PackageManagementProvider

Specifies the name of a package management provider.

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

PowerShellGet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ProviderName

Specifies one or more package provider names. Separate multiple package provider names with commas. Use Get-PackageProvider to get a list of available package providers.

参数属性

类型:

String[]

默认值:None
接受的值:Bootstrap, NuGet, PowerShellGet
支持通配符:False
不显示:False
别名:Provider

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-RequiredVersion

Specifies the exact version of the package to find.

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Scope

Specifies the search scope for the package.

参数属性

类型:String
默认值:None
接受的值:CurrentUser, AllUsers
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-SkipDependencies

Switch that specifies to skip finding any package dependencies.

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

NuGet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-SkipPublisherCheck

Allows you to get a package version that is newer than your installed version. For example, an installed package that is digitally signed by a trusted publisher but a new version isn't digitally signed.

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

PowerShellGet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Type

Specifies whether to search for packages with a module, a script, or either.

参数属性

类型:String
默认值:None
接受的值:Module, Script, All
支持通配符:False
不显示:False

参数集

PowerShellGet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

输出

Microsoft.PackageManagement.Packaging.SoftwareIdentity

This cmdlet returns a SoftwareIdentity object for each installed package that matches the parameters. By default, it returns every installed package.

备注

Including a package provider in a command can make dynamic parameters available to a cmdlet. Dynamic parameters are specific to a package provider. The Get-Help cmdlet lists a cmdlet's parameter sets and includes the provider's parameter set. For example, Get-Package has the PowerShellGet parameter set that includes -NoPathUpdate, AllowClobber, and SkipPublisherCheck.

Important

As of April 2020, the PowerShell Gallery no longer supports Transport Layer Security (TLS) versions 1.0 and 1.1. If you are not using TLS 1.2 or higher, you will receive an error when trying to access the PowerShell Gallery. Use the following command to ensure you are using TLS 1.2:

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

For more information, see the announcement in the PowerShell blog.