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
指定的腳本發佈至在線資源庫。
範例
範例 1:Create 腳本檔案、將內容新增至腳本檔案,並加以發佈
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-ScriptFileInfo
Demo-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
強制執行命令而不要求使用者確認。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-LiteralPath
指定一個或多個位置的路徑。 不同於 Path 參數, LiteralPath 參數的值會與輸入完全相同。 沒有字元會被視為萬用字元。 如果路徑包含逸出字元,請以單引弧括住這些字元。 單引號告知 Windows PowerShell 不要將任何字元視為逸出序列。
Type: | String |
Aliases: | PSPath |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-NuGetApiKey
指定您想要用來將文稿發佈至在線資源庫的 API 金鑰。 API 金鑰是在線資源庫中設定檔的一部分。 如需詳細資訊,請參閱 管理 API 金鑰。
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 |
輸入
輸出
備註
重要
從 2020 年 4 月起,PowerShell 資源庫已不再支援傳輸層安全性 (TLS) 1.0 和 1.1 版。 如果您不是使用 TLS 1.2 或更高版本,您在嘗試存取 PowerShell 資源庫時將會收到錯誤。 使用下列命令來確保您使用的是 TLS 1.2:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
如需詳細資訊,請參閱 PowerShell 部落格中的公告 \(英文\)。