| external help file | PSModule-help.xml |
|---|---|
| Locale | en-US |
| Module Name | PowerShellGet |
| ms.date | 03/27/2020 |
| online version | https://learn.microsoft.com/powershell/module/powershellget/publish-script?view=powershellget-2.x&WT.mc_id=ps-gethelp |
| schema | 2.0.0 |
| title | Publish-Script |
Publishes a script.
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>]
The Publish-Script cmdlet publishes the specified script to the online gallery.
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.ps1Version 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.
Specifies a user account that has rights to publish the script.
Type: System.Management.Automation.PSCredential
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: FalseForces the command to run without asking for user confirmation.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies 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.
Type: System.String
Parameter Sets: LiteralPathParameterSet
Aliases: PSPath
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: FalseSpecifies 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.
Type: System.String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies a path to one or more locations. Wildcards are permitted. The default location is the current directory.
Type: System.String
Parameter Sets: PathParameterSet
Aliases:
Required: True
Position: Named
Default value: <Current location>
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: TrueSpecifies the friendly name of a repository that has been registered by running
Register-PSRepository.
Type: System.String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalsePrompts you for confirmation before running the cmdlet.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseShows what would happen if the cmdlet runs. The cmdlet is not run.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -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