Save-Package

Saves packages to the local computer without installing them.

语法

PackageBySearch

Save-Package
    [-Name] <String[]>
    [-RequiredVersion <String>]
    [-MinimumVersion <String>]
    [-MaximumVersion <String>]
    [-Source <String[]>]
    [-Path <String>]
    [-LiteralPath <String>]
    [-Credential <PSCredential>]
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-AllVersions]
    [-Force]
    [-ForceBootstrap]
    [-WhatIf]
    [-Confirm]
    [-ProviderName <String[]>]
    [<CommonParameters>]

PackageByInputObject

Save-Package
    -InputObject <SoftwareIdentity>
    [-Path <String>]
    [-LiteralPath <String>]
    [-Credential <PSCredential>]
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-AllVersions]
    [-Force]
    [-ForceBootstrap]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

NuGet:PackageByInputObject

Save-Package
    [-Path <String>]
    [-LiteralPath <String>]
    [-Credential <PSCredential>]
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-AllVersions]
    [-Force]
    [-ForceBootstrap]
    [-WhatIf]
    [-Confirm]
    [-ConfigFile <String>]
    [-SkipValidate]
    [-Headers <String[]>]
    [-FilterOnTag <String[]>]
    [-Contains <String>]
    [-AllowPrereleaseVersions]
    [<CommonParameters>]

NuGet

Save-Package
    [-Path <String>]
    [-LiteralPath <String>]
    [-Credential <PSCredential>]
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-AllVersions]
    [-Force]
    [-ForceBootstrap]
    [-WhatIf]
    [-Confirm]
    [-ConfigFile <String>]
    [-SkipValidate]
    [-Headers <String[]>]
    [-FilterOnTag <String[]>]
    [-Contains <String>]
    [-AllowPrereleaseVersions]
    [<CommonParameters>]

PowerShellGet:PackageByInputObject

Save-Package
    [-Path <String>]
    [-LiteralPath <String>]
    [-Credential <PSCredential>]
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-AllVersions]
    [-Force]
    [-ForceBootstrap]
    [-WhatIf]
    [-Confirm]
    [-AllowPrereleaseVersions]
    [-PackageManagementProvider <String>]
    [-PublishLocation <String>]
    [-ScriptSourceLocation <String>]
    [-ScriptPublishLocation <String>]
    [-Type <String>]
    [-Filter <String>]
    [-Tag <String[]>]
    [-Includes <String[]>]
    [-DscResource <String[]>]
    [-RoleCapability <String[]>]
    [-Command <String[]>]
    [-AcceptLicense]
    [<CommonParameters>]

PowerShellGet

Save-Package
    [-Path <String>]
    [-LiteralPath <String>]
    [-Credential <PSCredential>]
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-AllVersions]
    [-Force]
    [-ForceBootstrap]
    [-WhatIf]
    [-Confirm]
    [-AllowPrereleaseVersions]
    [-PackageManagementProvider <String>]
    [-PublishLocation <String>]
    [-ScriptSourceLocation <String>]
    [-ScriptPublishLocation <String>]
    [-Type <String>]
    [-Filter <String>]
    [-Tag <String[]>]
    [-Includes <String[]>]
    [-DscResource <String[]>]
    [-RoleCapability <String[]>]
    [-Command <String[]>]
    [-AcceptLicense]
    [<CommonParameters>]

说明

The Save-Package cmdlet saves packages to the local computer but doesn't install the packages. This cmdlet saves the newest version of a package unless you specify a RequiredVerion. The Path and LiteralPath parameters are mutually exclusive, and cannot be added to the same command.

示例

Example 1: Save a package to the local computer

This example saves the newest version of the package to a directory on the local computer. The package's dependencies are download with the package.

PS> Save-Package -Name NuGet.Core -ProviderName NuGet -Path C:\LocalPkg
Name                    Version    Source    Summary
----                    -------    ------    -------
Microsoft.Web.Xdt       3.0.0      Nuget     Microsoft Xml Document Transformation (XDT) enables...
NuGet.Core              2.14.0     Nuget     NuGet.Core is the core framework assembly for NuGet...

Save-Package uses the Name parameter to specify the package. The package is downloaded from the repository specified by the ProviderName parameter. The Path parameter determines where the package is saved.

Example 2: Save a specific package version

This example specifies the package version and saves it to a directory on the local computer.

PS> Save-Package -Name NuGet.Core -RequiredVersion 2.9.0 -ProviderName NuGet -Path C:\LocalPkg
Name                    Version    Source    Summary
----                    -------    ------    -------
Microsoft.Web.Xdt       3.0.0      Nuget     Microsoft Xml Document Transformation (XDT) enables...
NuGet.Core              2.9.0      Nuget     NuGet.Core is the core framework assembly for NuGet...

Save-Package uses the Name parameter to specify the package. RequiredVersion indicates a specific package version. The package is downloaded from the repository specified by the ProviderName parameter. The Path parameter determines where the package is saved.

Example 3: Use Find-Package to save a package

This command uses Find-Package to locate the newest version of the package and sends the object to Save-Package.

PS> Find-Package -Name NuGet.Core -ProviderName NuGet | Save-Package -Path C:\LocalPkg

Find-Package uses the Name parameter to specify the package. The package is downloaded from the repository specified by the ProviderName parameter. The object is sent down the pipeline to Save-Package. The Path parameter determines where the package is saved.

Example 4: Save and install the package

The newest version of the package and its dependencies are downloaded and installed on the local computer.

PS> Save-Package -Name NuGet.Core -ProviderName NuGet -Path C:\LocalPkg
PS> Install-Package C:\LocalPkg\NuGet.Core.2.14.0.nupkg

Save-Package downloads the package file and its dependencies to the local computer. Install-Package installs the package and dependencies from the specified directory.

参数

-AcceptLicense

Automatically accept the license agreement during installation if the package requires it.

参数属性

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

参数集

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

-AllowPrereleaseVersions

Allows packages marked as Prerelease to be saved.

参数属性

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

参数集

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

-AllVersions

Indicates that this cmdlet saves all available versions of the package.

参数属性

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

参数集

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

-Command

Specifies one or more commands included in the package.

参数属性

类型:

String[]

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

参数集

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

-ConfigFile

Specifies a configuration File.

参数属性

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

参数集

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

-Confirm

Prompts you for confirmation before running the cmdlet.

参数属性

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

参数集

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

-Contains

Save-Package gets objects if any item in the object's property values are an exact match for the specified value.

参数属性

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

参数集

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

-Credential

Specifies a user account that has permission to save a package from a specified package provider or source.

参数属性

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

参数集

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

-DscResource

Specifies one or more Desired State Configuration (DSC) resources for the package.

参数属性

类型:

String[]

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

参数集

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

-Filter

Specifies a filter for the package.

参数属性

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

参数集

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

-FilterOnTag

Specifies the tag that filters the results. Results that don't contain the specified tag are excluded.

参数属性

类型:

String[]

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

参数集

NuGet:PackageByInputObject
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):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 Save-Package forces PackageManagement to automatically install the package provider for the specified package.

参数属性

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

参数集

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

-Headers

Specifies the headers for the package.

参数属性

类型:

String[]

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

参数集

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

-Includes

Indicates the resources that the package includes.

参数属性

类型:

String[]

默认值:None
接受的值:DscResource, Cmdlet, Function, Workflow, RoleCapability
支持通配符:False
不显示:False

参数集

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

-InputObject

A software ID object that represents the package that you want to save. Software IDs are part of the results of the Find-Package cmdlet.

参数属性

类型:Microsoft.PackageManagement.Packaging.SoftwareIdentity
默认值:None
支持通配符:False
不显示:False

参数集

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

-LiteralPath

Specifies the literal path to which you want to save the package. You cannot add both this parameter and the Path parameter to the same command.

参数属性

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

参数集

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

-MaximumVersion

Specifies the maximum version of the package that you want to save.

参数属性

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

参数集

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

-MinimumVersion

Specifies the minimum version of the package that you want to find.

参数属性

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

参数集

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

-Name

Specifies one or more package names.

参数属性

类型:

String[]

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

参数集

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

-PackageManagementProvider

Specifies a package management provider.

参数属性

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

参数集

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

-Path

Specifies the location on the local computer to store the package.

参数属性

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

参数集

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

-ProviderName

Specifies one or more provider names.

参数属性

类型:

String[]

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

参数集

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

-Proxy

Specifies a proxy server for the request, rather than a direct connection to the internet resource.

参数属性

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

参数集

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

-ProxyCredential

Specifies a user account that has permission to use the proxy server that is specified by the Proxy parameter.

参数属性

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

参数集

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

-PublishLocation

Specifies the publish location.

参数属性

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

参数集

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

-RequiredVersion

Specifies the exact version of the package to save.

参数属性

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

参数集

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

-RoleCapability

Specifies an array of role capabilities.

参数属性

类型:

String[]

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

参数集

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

-ScriptPublishLocation

Specifies the script publish location.

参数属性

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

参数集

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

-ScriptSourceLocation

Specifies the script source location.

参数属性

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

参数集

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

-SkipValidate

Switch that skips validating the credentials of a package.

参数属性

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

参数集

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

-Source

Specifies one or more package sources.

参数属性

类型:

String[]

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

参数集

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

-Tag

Specifies a tag to search for within the package metadata.

参数属性

类型:

String[]

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

参数集

PowerShellGet:PackageByInputObject
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):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:PackageByInputObject
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False
PowerShellGet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

参数属性

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

参数集

(All)
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

You can pipe a SoftwareIdentity object to this cmdlet.

输出

None

This cmdlet returns no output.

备注

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.