https://docs.microsoft.com/en-us/powershell/gallery/getting-started
https://www.powershellgallery.com/packages?q=PowerShell-Beautifier
Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2
注册完账号,在publish页面看到提示
自己的Powershell脚本应该只算是script
https://docs.microsoft.com/en-us/powershell/module/powershellget/publish-script?view=powershell-6
API keys
An API key is a token that can identify you to PowerShell Gallery. To publish a package to the PowerShell Gallery, run the
Publish-Module or Publish-Script cmdlet, and specify your personal API key as the value of the NuGetApiKey parameter.
Always keep your API keys a secret! If one of your keys is accidentally revealed泄露, you can always generate a new one at any time. You can also remove existing API keys if necessary.
Note: To install packages from https://www.powershellgallery.com requires the latest version of PowerShellGet module.
错误处理
直接publish script,提示错误
http://www.brianbunke.com/blog/2017/01/09/publishing-scripts/
Publish-Script -Path .\chuck.ps1 -NuGetApiKey mykey
Test-ScriptFileInfo : PSScriptInfo is not specified in the script file 'C:\Users\clu\source\repos\GitHub\ChuckLu\Scripts\Powershell\chuck.ps1'. You can use the Update-ScriptFileInfo with -Force or New-ScriptFileInfo cmdlet to add the PSScriptInfo to the script file.
At C:\program files\powershell\6-preview\Modules\PowerShellGet\PSModule.psm1:10727 char:29
+ $PSScriptInfo = Test-ScriptFileInfo -Path $scriptFilePath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (C:\Users\clu\source\u2026owershell\chuck.ps1:String) [Test-ScriptFileInfo], ArgumentException
+ FullyQualifiedErrorId : MissingPSScriptInfo,Test-ScriptFileInfo
需要https://docs.microsoft.com/en-us/powershell/module/powershellget/new-scriptfileinfo?view=powershell-6
发现New-ScriptFileInfo无法对现有文件操作,改用Update-ScriptFileInfo。还需要加上force参数
Update-ScriptFileInfo .\chuck.ps1 -Author "[email protected]" -Description "Chuck's scripts" -Force -Verbose
发布超时
Publish-PSArtifactUtility : Failed to publish script 'chuck': 'info : Pushing chuck.1.0.0.nupkg to 'https://www.powershellgallery.com/api/v2/package/'...
info : PUT https://www.powershellgallery.com/api/v2/package/
info : An error was encountered when fetching 'PUT https://www.powershellgallery.com/api/v2/package/'. The request will now be retried.
info : An error occurred while sending the request.
info : The server returned an invalid or unrecognized response.
info : PUT https://www.powershellgallery.com/api/v2/package/
info : An error was encountered when fetching 'PUT https://www.powershellgallery.com/api/v2/package/'. The request will now be retried.
info : An error occurred while sending the request.
info : The server returned an invalid or unrecognized response.
info : PUT https://www.powershellgallery.com/api/v2/package/
error: The operation was canceled.
error: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
error: The I/O operation has been aborted because of either a thread exit or an application request.
error: Pushing took too long. You can change the default timeout of 300 seconds by using the --timeout
'.
At C:\Program Files\PowerShell\Modules\PowerShellGet\2.1.2\PSModule.psm1:10952 char:17
+ ... Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : FailedToPublishTheScript,Publish-PSArtifactUtility