Save-Module

將模組及其相依性儲存在本機電腦上,但不會安裝模組。

Syntax

Save-Module
    [-Name] <String[]>
    [-MinimumVersion <String>]
    [-MaximumVersion <String>]
    [-RequiredVersion <String>]
    [-Repository <String[]>]
    [-Path] <String>
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-Credential <PSCredential>]
    [-Force]
    [-AllowPrerelease]
    [-AcceptLicense]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]
Save-Module
    [-Name] <String[]>
    [-MinimumVersion <String>]
    [-MaximumVersion <String>]
    [-RequiredVersion <String>]
    [-Repository <String[]>]
    -LiteralPath <String>
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-Credential <PSCredential>]
    [-Force]
    [-AllowPrerelease]
    [-AcceptLicense]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]
Save-Module
    [-InputObject] <PSObject[]>
    -LiteralPath <String>
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-Credential <PSCredential>]
    [-Force]
    [-AcceptLicense]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]
Save-Module
    [-InputObject] <PSObject[]>
    [-Path] <String>
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-Credential <PSCredential>]
    [-Force]
    [-AcceptLicense]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

Cmdlet 會 Save-Module 從已註冊的存放庫下載模組和任何相依性。 Save-Module 會下載並儲存模組的最新版本。 檔案會儲存到本機電腦上的指定路徑。 模組未安裝,但內容可供系統管理員檢查。 然後,可以將儲存的模組複製到離線電腦的適當 $env:PSModulePath 位置。

這是Microsoft.PowerShell.PSResourceGet中 Cmdlet 的 Proxy Cmdlet Save-PSResource 。 如需詳細資訊,請參閱 Save-PSResource

範例

範例 1:儲存模組

在此範例中,模組及其相依性會儲存至本機電腦。

Save-Module -Name PowerShellGet -Path C:\Test\Modules -Repository PSGallery
Get-ChildItem -Path C:\Test\Modules

Directory: C:\Test\Modules

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         7/1/2019     13:31                PackageManagement
d-----         7/1/2019     13:31                PowerShellGet

Save-Module 會使用 Name 參數來指定模組 PowerShellGetPath參數會指定儲存已下載模組的位置。 存放庫參數會指定已註冊的存放庫PSGallery。 下載完成後, Get-ChildItem 會顯示儲存檔案之 Path 的內容。

範例 2:儲存模組的特定版本

此範例示範如何使用 MaximumVersionRequiredVersion 之類的參數來指定模組版本。

Save-Module -Name PowerShellGet -Path C:\Test\Modules -Repository PSGallery -MaximumVersion 2.1.0
Get-ChildItem -Path C:\Test\Modules\PowerShellGet\

Directory: C:\Test\Modules\PowerShellGet

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         7/1/2019     13:40                2.1.0

Save-Module 會使用 Name 參數來指定模組 PowerShellGetPath參數會指定儲存已下載模組的位置。 存放庫參數會指定已註冊的存放庫PSGalleryMaximumVersion 指定下載並儲存 2.1.0 版 。 下載完成後, Get-ChildItem 會顯示儲存檔案之 Path 的內容。

範例 3:尋找並儲存特定版本的模組

在此範例中,在存放庫中找到必要的模組版本,並儲存至本機電腦。

Find-Module -Name PowerShellGet -Repository PSGallery -RequiredVersion 1.6.5 |
  Save-Module -Path C:\Test\Modules
Get-ChildItem -Path C:\Test\Modules\PowerShellGet

Directory: C:\Test\Modules\PowerShellGet

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         7/1/2019     14:04                1.6.5

Find-Module 會使用 Name 參數來指定模組 PowerShellGet存放庫參數會指定已註冊的存放庫PSGalleryRequiredVersion 指定 1.6.5 版

物件會向下傳送至 Save-Module 管線。 Path參數會指定儲存已下載模組的位置。 下載完成後, Get-ChildItem 會顯示儲存檔案之 Path 的內容。

參數

-AcceptLicense

Proxy Cmdlet 會忽略此參數,因為它不受 支援 Save-PSResource

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-AllowPrerelease

可讓您儲存標示為發行前版本的模組。

Proxy Cmdlet 會將此參數對應至 的 Save-PSResource發行前版本參數。

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

在執行 之前 Save-Module ,提示您確認。

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Credential

指定有權儲存模組的使用者帳戶。

Type:PSCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Force

Proxy Cmdlet 會忽略此參數,因為它不受 支援 Save-PSResource

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InputObject

接受 PSRepositoryItemInfo 物件。 例如,輸出 Find-Module 至變數,並使用該變數作為 InputObject 引數。

Type:PSObject[]
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-LiteralPath

指定一個或多個位置的路徑。 LiteralPath參數的值與輸入完全相同。 沒有字元會被視為萬用字元。 如果路徑包含逸出字元,請用單引號括住它們。 PowerShell 不會將以單引號括住的任何字元解譯為逸出序列。

Proxy Cmdlet 會將此參數對應至 的 Save-PSResourcePath參數。

Type:String
Aliases:PSPath
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-MaximumVersion

Proxy Cmdlet 會使用此參數的值來建立 NuGet 版本搜尋字串,以搭配 的 Save-PSResourceVersion參數使用。

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-MinimumVersion

Proxy Cmdlet 會使用此參數的值來建立 NuGet 版本搜尋字串,以搭配 的 Save-PSResourceVersion參數使用。

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Name

指定要儲存的模組名稱陣列。

Type:String[]
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Path

指定要儲存已儲存模組之本機電腦上的位置。 接受萬用字元。

Type:String
Position:1
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:True

-Proxy

Proxy Cmdlet 會忽略此參數,因為它不受 支援 Save-PSResource

Type:Uri
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-ProxyCredential

Proxy Cmdlet 會忽略此參數,因為它不受 支援 Save-PSResource

Type:PSCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Repository

指定已執行 Register-PSRepository 註冊之存放庫的易記名稱。 用來 Get-PSRepository 顯示已註冊的存放庫。

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-RequiredVersion

Proxy Cmdlet 會使用此參數的值來建立 NuGet 版本搜尋字串,以搭配 的 Save-PSResourceVersion參數使用。

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

顯示執行時 Save-Module 會發生什麼情況。 不會執行此 Cmdlet。

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

輸入

String[]

PSObject[]

String

Uri

PSCredential

輸出

Object

備註

PowerShell 資源庫不再支援傳輸層安全性 (TLS) 1.0 和 1.1 版。 您必須使用 TLS 1.2 或更高版本。 使用下列命令來確保您使用的是 TLS 1.2:

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