Publish-Script

發佈腳本。

Syntax

Publish-Script
       -Path <String>
       [-NuGetApiKey <String>]
       [-Repository <String>]
       [-Credential <PSCredential>]
       [-Force]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Publish-Script
       -LiteralPath <String>
       [-NuGetApiKey <String>]
       [-Repository <String>]
       [-Credential <PSCredential>]
       [-Force]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]

Description

Cmdlet 會將 Publish-Script 指定的腳本發佈至線上資源庫。

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

範例

範例 1:建立腳本檔案、將內容新增至其中,並加以發佈

Cmdlet 會 New-ScriptFileInfo 建立名為 的 Demo-Script.ps1 腳本檔案。 Get-Content 會顯示 的內容 Demo-Script.ps1 。 Cmdlet 會將 Add-Content 函式和工作流程新增至 Demo-Script.ps1

$newScriptInfo = @{
  Path = 'D:\ScriptSharingDemo\Demo-Script.ps1'
  Version = '1.0'
  Author = 'author@contoso.com'
  Description = "my test script file description goes here"
}
New-ScriptFileInfo @newScriptInfo
Get-Content -Path $newScriptInfo.Path

<#PSScriptInfo

.VERSION 1.0

.AUTHOR pattif@microsoft.com

.COMPANYNAME

.COPYRIGHT

.TAGS

.LICENSEURI

.PROJECTURI

.ICONURI

.EXTERNALMODULEDEPENDENCIES

.REQUIREDSCRIPTS

.EXTERNALSCRIPTDEPENDENCIES

.RELEASENOTES
#>

<#
.DESCRIPTION
 my test script file description goes here
#>
Param()

Add-Content -Path D:\ScriptSharingDemo\Demo-Script.ps1 -Value @"

Function Demo-ScriptFunction { 'Demo-ScriptFunction' }

Workflow Demo-ScriptWorkflow { 'Demo-ScriptWorkflow' }

Demo-ScriptFunction
Demo-ScriptWorkflow
"@
Test-ScriptFileInfo -Path D:\ScriptSharingDemo\Demo-Script.ps1

Version    Name                 Author                   Description
-------    ----                 ------                   -----------
1.0        Demo-Script          author@contoso.com       my test script file description goes here

Publish-Script -Path D:\ScriptSharingDemo\Demo-Script.ps1 -Repository LocalRepo1
Find-Script -Repository LocalRepo1 -Name "Demo-Script"

Version    Name                 Type       Repository    Description
-------    ----                 ----       ----------    -----------
1.0        Demo-Script          Script     LocalRepo1    my test script file description goes here

Cmdlet 會 Test-ScriptFileInfoDemo-Script.ps1 驗證 。 Cmdlet 會將 Publish-Script 腳本發佈至 LocalRepo1 存放庫。 最後, Find-Script用於在LocalRepo1存放庫中搜尋 Demo-Script.ps1

參數

-Confirm

在執行 Cmdlet 前提示您確認。

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 會忽略此參數,因為它不受 支援 Publish-PSResource

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

-LiteralPath

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

參數會對應至 Cmdlet 的 Publish-PSResourcePath參數。

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

-NuGetApiKey

指定您想要用來將腳本發佈至線上資源庫的 API 金鑰。 API 金鑰是線上資源庫中設定檔的一部分。 如需詳細資訊,請參閱 管理 API 金鑰

參數會對應至 Cmdlet 的 Publish-PSResourceApiKey參數。

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

-Path

指定一個或多個位置的路徑。 允許使用萬用字元。 預設位置是目前的目錄。

Type:String
Position:Named
Default value:<Current location>
Required:True
Accept pipeline input:True
Accept wildcard characters:True

-Repository

指定已藉由執行 Register-PSRepository 來註冊之存放庫的易記名稱。

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

-WhatIf

顯示執行 Cmdlet 後會發生的情況。 Cmdlet 並不會執行。

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

輸入

String

PSCredential

輸出

Object

備註

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

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