Publish-Script -Path "path-to-script.ps1" -NuGetApiKey 123456789
after doing that, I get this error in PowerShell 7.3:
Write-Error: Failed to generate the compressed file for script 'C:\Program Files\dotnet\dotnet.exe failed to pack: error '.
and I get this error in PowerShell 5.1:
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\2.2.5\PSModule.psm1:11338 char:17
+ ... Publish-PSArtifactUtility #PublishPSArtifactUtility_Param ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : FailedToCreateCompressedScript,Publish-PSArtifactUtility
my script has no dependency.
this problem has been going on for the past 2 weeks.
I even gave my script with API key to a friend from another country and they receive the same error too.
how can I fix this? I've published previous versions of this script before at least 6 times.
I've tried resetting my API key and running PowerShell as admin, didn't fix it.
Update:
I installed .NET 7 runtimes x64 and used this command from this answer on PowerShell 5.1:
# find the file having wrong .NET version
$path = Get-ChildItem (Get-Module PowerShellGet -ListAvailable).ModuleBase -Recurse -File |
Select-String -Pattern netcoreapp2.0 | ForEach-Object Path
# unload the module
Remove-Module PowerShellGet -Verbose -Force -EA 0
# update the file
$path | ForEach-Object {
(Get-Content -LiteralPath $_ -Raw).Replace('netcoreapp2.0', 'net7') |
Set-Content $_
}
Import-Module PowerShellGet -Force -Verbose
# now try to publish
but still getting 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\2.2.5\PSModule.psm1:11338 char:17
+ ... Publish-PSArtifactUtility #PublishPSArtifactUtility_Param ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : FailedToCreateCompressedScript,Publish-PSArtifactUtility
enter image description here
I fixed the problem by installing .NET Core 2.0 SDK
https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-2.1.202-windows-x64-installer
Related
I'm totally noob in powershell scripting. Trying to remove some fonts that are installed on the system. I saved the fonts in the following folder "C:\Temp\fonts\fonts-to-be-installed". The script should find the font name in that folder and remove the matching fonts from registry and C:\Windows\Fonts folder. However, when I run this script it doesn't work. I don't get any error messages. Wondering whats's missing here. Any hints would be appreciated.
# Remove fonts
$Fontstoberemoved = Get-ChildItem -Path "C:\Temp\fonts\fonts-to-be-installed\" | Where-Object Name -Like "*.ttf"
foreach ($font in $Fontstoberemoved) {
Write-Output "Deleting item: 'C:\Windows\Fonts\$font.Name'"
Remove-Item -Path "C:\Windows\Fonts\$font.Name" -Force
Write-Output "Deleting item: 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\$font.Name'"
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" -Name $font.Name -Force
}
I've just modified the script to remove the fonts from one more location as below:
**Remove-Item -Path "$env:LOCALAPPDATA\Microsoft\Windows\Fonts\$font" -Force**
Now I'm getting the following error message:
"Remove-Item : Cannot find path 'C:\Users\xxxx\AppData\Local\Microsoft\Windows\Fonts\Linotype - NHaasGroteskTXPro-56It.ttf' because it does not exist. At line:4 char:1
+ Remove-Item -Path "$env:LOCALAPPDATA\Microsoft\Windows\Fonts\$font" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\xxxx...kTXPro-56It.ttf:String) [Remove-Item], ItemNotFoundEx ception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand"
The fonts are still in that folder. When I try to manually delete the fonts I get a warning message that the file is open in system. Wondering how to detect which process is using the fonts?
I have a few scripts where I import all VMware-Modules for simplicity. This has worked all the time - but now on one server it won't.
PS C:\Temp> Import-Module VMware.*
Import-Module : The specified module 'VMware.*' was not loaded because no valid module file was found in any module
directory.
At line:1 char:1
+ Import-Module VMware.*
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (VMware.*:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
I just copied the modules to C:\Windows\System32\WindowsPowerShell\v1.0\Modules.
When I use the full name (Import-Module VMware.VimAutomation.Core) it works as usual.
How can I fix this? They appear correctly when I do a Get-Module -ListAvailable.
Import-Module doesn't support wildcards. What you could do, however, is get all the module names using Get-Module and then pipe them into a ForEach-Object command.
I believe this will achieve what you are after:
Get-Module -Name "VMWave.*" | ForEach-Object { Import-Module $_; Write-Host "Imported Module $_"}
I employ a user-defined function, called searchfor, from a PowerShell console prompt (Run as Administrator) to find files containing strings:
PS repo> gc Function:\searchfor
param([string]$root, [string[]]$includeexpression, [string]$regexp)
$fullpath = convert-path $root
Get-ChildItem -force -recurse $fullpath -include $includeexpression | Select-String $regexp
This has recently started to fail on some files with the following "cannot be read/access denied" error message:
Select-String : The file C:\builds\repo\LightweightSerialization\LightweightSerializationWriter.cs cannot be read: Access to the path 'C:\builds\repo\LightweightSerialization\LightweightSerializationWriter.cs' is denied.
At C:\Users\schlagermeier\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:174 char:71
+ ... recurse $fullpath -include $includeexpression | Select-String $regexp
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-String], ArgumentException
+ FullyQualifiedErrorId : ProcessingFile,Microsoft.PowerShell.Commands.SelectStringCommand
An attempt to read the file interactively with Get-Content fails with the same error. However, if I launch a Command Prompt (cmd.exe), also using Run as Administrator, I can read the file content with the type command.
I've looked at the file's permissions and acl, and it doesn't appear any different to others in the same folder which can be read by PowerShell. Can anybody suggest any possible causes and how these might be identified and fixed?
I'm trying to use a script I found on the internet to copy all files in a directory but I can't get it to work. Can anybody help debug? I'm guessing the script was used to transfer windows/windows but I need windows --> Linux.
https://www.powershellmagazine.com/2013/12/17/pstip-copying-folders-using-copy-vmfile-cmdlet-in-windows-server-2012-r2-hyper-v/
Get-ChildItem C:\tmp -Recurse -File | % { Copy-VMFile -Name "OpenProject8.3" -SourcePath $_.FullName -DestinationPath "/tmp/" -FileSource Host }
The issue seems to be related to the sourcepath, but im not 100%.
Copy-VMFile : Failed to initiate copying files to the guest.
Failed to copy the source file 'C:\tmp\svn-repositories-20200212010002.tar.gz' to the destination '/tmp/' in the guest.
At line:1 char:43
+ ... -File | % { Copy-VMFile -Name "OpenProject8.3" -SourcePath $_.FullNam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-VMFile], VirtualizationException
+ FullyQualifiedErrorId : OperationFailed,Microsoft.HyperV.PowerShell.Commands.CopyVMFile
Well.... I feel stupid! The issue was that earlier testing the x-fer had succeeded and then when the file exists, Copy-VMFile won't overwrite the file (even though it uses root account...) and gives a non-descriptive error! The code above works fine as is.
Got this error while installing docker on windows server 2016. any idea?
PS C:\Users\Administrator> Install-Package -Name docker -ProviderName
DockerMsftProvider Install-Package : Cannot rename because item at
'C:\Program Files\dummyName' does not exist. At line:1 char:1
+ Install-Package -Name docker -ProviderName DockerMsftProvider
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package],
Exception
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RenameItemCommand,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
I found this issue on: https://www-01.ibm.com/support/docview.wss?uid=swg22009935
The problem seems to be caused by Symantec Antivirus. To stop it press Win Key + R key and then type in smc -stop or smc start (depending on what you want to do). I did this and the error did not appear anymore.
reply here worked for me...
Cannot Install Docker on Windows 10
Open Windows defender
Disable Ransomware protection
Install Docker
optional Enable Ransomware protection
Rename the docker folder to become Docker
$dummyName = 'dummyName'
$null = Rename-Item -Path $script:pathDockerRoot -NewName $env:ProgramFiles\$dummyName
while (!(Test-Path $env:ProgramFiles\$dummyName))
{
Start-Sleep 1
$null = Rename-Item -Path $script:pathDockerRoot -NewName $env:ProgramFiles\$dummyName -ErrorAction Continue -Verbose
}
$null = Rename-Item -Path $env:ProgramFiles\$dummyName -NewName $script:pathDockerRoot