Since we had announced the retirement of the TechNet gallery last year, I’ve been slowly moving my scripts to the PowerShell gallery. I haven’t posted any new scripts in a couple of months and wrote a new one today. Uploading a script to the PowerShell Gallery typically requires using the
Publish-Script cmdlet in conjunction with an API key.
And received this delightfully cryptic error:
Publish-PSArtifactUtility : Failed to generate the compressed file for script ‘C:\Program Files\dotnet\dotnet.exe failed to pack: error
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\18.104.22.168\PSModule.psm1:11336 char:17
+ … Publish-PSArtifactUtility @PublishPSArtifactUtility_Param …
+ CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : FailedToCreateCompressedScript,Publish-PSArtifactUtility
I figured since I hadn’t done it in a while, maybe something was wrong with PowerShellGet, so I ran
Update-Module PowerShellGet. Same result.
The ultimate fix was equally as cryptic as the error message. From a new elevated PowerShell prompt, run the following command:
Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile "$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe"
From there, you should be able to run Publish-Script successfully.