The Publish-Script cmdlet publishes the specified script to the online gallery.
Przykłady
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()
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.
Parametry
-Confirm
Prompts you for confirmation before running the cmdlet.
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.
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.
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:
Źródło tej zawartości można znaleźć w witrynie GitHub, gdzie można również tworzyć i przeglądać problemy i żądania ściągnięcia. Więcej informacji znajdziesz w naszym przewodniku dla współtwórców.