PowerShell Gallery

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

 

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 "chuck.lu@qq.com" -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 <seconds> option with the push command.
'.
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

 

转载于:https://www.cnblogs.com/chucklu/p/10535169.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值