Publish-Script
發佈腳本。
語法
PathParameterSet (預設值)
Publish-Script
-Path <String>
[-NuGetApiKey <String>]
[-Repository <String>]
[-Credential <PSCredential>]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
LiteralPathParameterSet
Publish-Script
-LiteralPath <String>
[-NuGetApiKey <String>]
[-Repository <String>]
[-Credential <PSCredential>]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
Cmdlet 會將 Publish-Script 指定的腳本發佈至在線資源庫。
這是 Publish-PSResource 中 Cmdlet 的 Proxy Cmdlet。 如需詳細資訊,請參閱 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-ScriptFileInfo 會 Demo-Script.ps1驗證 。 Cmdlet 會將 Publish-Script 腳本發佈至 LocalRepo1 存放庫。 最後。
Find-Script用來在 Demo-Script.ps1 存放庫中搜尋 。
參數
-Confirm
在執行 Cmdlet 之前,提示您進行確認。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | False |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | cf |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Credential
指定有權發佈腳本的用戶帳戶。
參數屬性
| 類型: | PSCredential |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-Force
Proxy Cmdlet 會忽略此參數,因為它不受 支援 Publish-PSResource。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-LiteralPath
指定通往一個或多個位置的路徑。 不同於 Path 參數, LiteralPath 參數的值會與輸入完全相同。 不會將任何字元解譯為通配符。 如果路徑包含逸出字元,請以單引弧括住它們。 單引號會告知 Windows PowerShell 不要將任何字元解譯為逸出序列。
參數會對應至 Cmdlet 的 Publish-PSResource 參數。
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | PSPath |
參數集
LiteralPathParameterSet
| Position: | Named |
| 必要: | True |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-NuGetApiKey
指定您想要用來將文稿發佈至在線資源庫的 API 金鑰。 API 金鑰是在線資源庫中設定檔的一部分。 如需詳細資訊,請參閱 管理 API 金鑰。
參數會對應至 Cmdlet 的 Publish-PSResource 參數。
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Path
指定通往一個或多個位置的路徑。 允許使用通配符。 預設位置是目前目錄。
參數屬性
| 類型: | String |
| 預設值: | <Current location> |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
PathParameterSet
| Position: | Named |
| 必要: | True |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-Repository
指定已執行 Register-PSRepository所註冊之存放庫的易記名稱。
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-WhatIf
顯示 Cmdlet 執行時會發生什麼事。 指令未執行。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | False |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | 無線 |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
CommonParameters
此 Cmdlet 支援一般參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters。
輸入
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