Publish-Script
Publishes a 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>]
说明
The Publish-Script
cmdlet publishes the specified script to the online gallery.
This is a proxy cmdlet for the Publish-PSResource
cmdlet in the
Microsoft.PowerShell.PSResourceGet. For more information, see
Publish-PSResource.
示例
Example 1: Create a script file, add content to it, and publish it
The New-ScriptFileInfo
cmdlet creates a script file named Demo-Script.ps1
. Get-Content
displays the content of Demo-Script.ps1
. The Add-Content
cmdlet adds a function and a workflow
to 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
The Test-ScriptFileInfo
cmdlet validates Demo-Script.ps1
. The Publish-Script
cmdlet publishes
the script to the LocalRepo1 repository. Finally. Find-Script
is used to search for
Demo-Script.ps1
in the LocalRepo1 repository.
参数
-Confirm
Prompts you for confirmation before running the cmdlet.
参数属性
类型: | SwitchParameter |
默认值: | False |
支持通配符: | False |
不显示: | False |
别名: | cf |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Credential
Specifies a user account that has rights to publish the script.
参数属性
类型: | PSCredential |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | True |
来自剩余参数的值: | False |
-Force
The proxy cmdlet ignores this parameter since it's not supported by Publish-PSResource
.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-LiteralPath
Specifies a path to one or more locations. Unlike the Path parameter, the value of the LiteralPath parameter is used exactly as entered. No characters are interpreted as wildcards. If the path includes escape characters, enclose them in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.
The parameter is mapped to the Path parameter of the Publish-PSResource
cmdlet.
参数属性
类型: | String |
默认值: | None |
支持通配符: | False |
不显示: | False |
别名: | PSPath |
参数集
LiteralPathParameterSet
Position: | Named |
必需: | True |
来自管道的值: | False |
来自管道的值(按属性名称): | True |
来自剩余参数的值: | False |
-NuGetApiKey
Specifies the API key that you want to use to publish a script to the online gallery. The API key is part of your profile in the online gallery. For more information see Managing API keys.
The parameter is mapped to the ApiKey parameter of the Publish-PSResource
cmdlet.
参数属性
类型: | String |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Path
Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory.
参数属性
类型: | String |
默认值: | <Current location> |
支持通配符: | True |
不显示: | False |
参数集
PathParameterSet
Position: | Named |
必需: | True |
来自管道的值: | False |
来自管道的值(按属性名称): | True |
来自剩余参数的值: | False |
-Repository
Specifies the friendly name of a repository that has been registered by running
Register-PSRepository
.
参数属性
类型: | String |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
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.
输入
输出
备注
The PowerShell Gallery no longer supports Transport Layer Security (TLS) versions 1.0 and 1.1. You must use TLS 1.2 or higher. Use the following command to ensure you are using TLS 1.2:
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12