I try to copy a DLL file from my computer to another and register it:
net use \\RemoteIp\C$\Dev 'pass'/USER:'user'
copy-item "D:\test.dll" -Destination "\\RemoteIp\c$\Dev";
regsvr32 "\\RemoteIp\C$\Dev\test.dll"
The problem that I have is that when I try to run this script from Octopus I receive this error :
Copy-Item : Cannot find path 'D:\test.dll' because it does
not exist.
At C:\Octopus\Work\20160606100457-74\Script.ps1:3 char:10
+ copy-item <<<< "D:\test.dll" -Destination "\RemoteIp\c$\Dev";
+ CategoryInfo : ObjectNotFound: (D:\test.dll
:String) [Copy-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyI
temCommand
The remote script failed with exit code 1
If I try to run these lines of code in PowerShell it works properly.
Any suggestions ?
Thank you
Actually this was my fault. When you are running a script in Octopus that is meant to run on the Deployment target:
you have to define your local pc with the ip address. For example, in my case I had to write the address "D:\test.dll" like this : "\192.168.00.00\D$\test.dll" .
For the regsvr32 problem, I added a bat file on the server that runs the regsvr32 instruction and I just call that file and it does the rest.
Hopefully that helps others :)
Related
I have installed scoop in my Windows PowerShell for ability to install some apps.
When I install app and then try to run it I get an error that there is no possibility to find shim file. 'C:\Windows\System32\apps\scoop\new' from my logs actually really doesn't exist. Maybe somebody had the same problem. I have found a clue that scoop could be out of date. I checked it and it really is but I cannot update it because i have still the same problem that it cannot read shim file.'scoop config rm SCOOP_REPO' also doesn't help. Any idea how to solve this problem?
PS C:\Windows\System32\apps\railway\current> scoop update
Updating Scoop...
Cannot open shim file for read.
Could not read shim file.
Remove-Item : Cannot find path 'C:\Windows\System32\apps\scoop\new' because it does not exist.
At C:\Windows\System32\apps\scoop\current\libexec\scoop-update.ps1:79 char:13
+ Remove-Item $newdir -Force -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Windows\System32\apps\scoop\new:String) [Remove-Item], ItemNotFoun
dException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
Scoop download failed. If this appears several times, try removing SCOOP_REPO by 'scoop config rm SCOOP_REPO'
I am trying to copy files from Windows 10 host to Ubuntu VM (Hyper-V) using this command:
Copy-VMFile "UbuntuVM" -SourcePath C:\Users\file.pcap -DestinationPath "~/opt/..../file.pcap" -CreateFullPath -FileSource Host
The destination path is my Ubuntu location, however it does not feel right to map it this way.
When executing the command in powershell it give the following:
Copy-VMFile : Failed to initiate copying files to the guest. Failed to copy the source file to
the destination
+ CategoryInfo : NotSpecified: (:) [Copy-VMFile], VirtualizationException
+ FullyQualifiedErrorId : OperationFailed,Microsoft.HyperV.PowerShell.Commands.CopyVMFile
The guest options are enabled.
Could somebody help me with this issue?
I've currently got a script that:
Loops through some files
Checks the name of the file
If there is no directory for the file it will create one
Moves the file into the directory
The moving logic works fine. However if a directory does not exist I am given this error (the path is valid, except it does not exist)
C:\Users\User\Documents\Directory\FileName : The term 'C:\Users\User\Documents\
Directory\FileName' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
C:\Users\User\Documents\Directory\FileName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\User\Documents\Directory\FileName) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The curious part is that it does actually create the folder - however it crashes my script.
Here's the problem part of the script
function CanCreate($dir) {
return !(Test-Path $dir)
}
if (CanCreate($fullDestinationPath)) {
New-Item $fullDestinationPath -ItemType Directory
}
md/mkdir behave differently to New-Item in that they do crash the script, however New-Item prints the error and continues (script seems to finish its job).
Edit:
The issue seems to stem from the fact that I am calling the script from another script.
$ScriptPath = "C:\Powershell Scripts\script.ps1"
& $ScriptPath | Invoke-Expression
The issue was with the fact that I was using | Invoke-Expression to trigger the script.
Simply calling & $ScriptPath, omitting the | Invoke-Expression, was enough to trigger the script.
Thanks everyone.
I'm not sure when this started... whenever I open PowerShell, I can't execute even the most basic commands. I always get the following error message:
PS C:\> dir
dir : Cannot find drive. A drive with the name '.' does not exist.
At line:1 char:1
+ dir
+ ~~~
+ CategoryInfo : ObjectNotFound: (.:String) [], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound
---
This had been working fine but now all of a sudden I can't do anything. I've tried removing PowerShell 4 and re-installing... no change. Sorry for the formatting here... It looks organized in my view above but the preview text looks horrid.
I don't remember ever having java installed, but looking at my regular %path% I see that %java_home% is in there, but the value is never used or defined anywhere. Once I removed that from my path, the error above went away.
Strange that it would even be an issue for powershell. You'd think it would just skip past a non-existent directory in my path and move onto the next one when resolving a command.
My script uses the Powershell splitpipeline module, to bring parallel process and queues features.
The script and the module are stored on shared server, like \server\c$ , the idea is be able to run it from any computer.
Tried to put at begining of the script import-module \\server\c$\SplitPipeline but I recieve the error:
import-module : Could not load file or assembly 'file://\\server\c$\SplitPipeline\SplitPipeline.dll' or one of its dependencies.
Operation is not supported. (Exception from HRESULT: 0x80131515)
At D:\scripts\powershell\OstReport_BETA-PIPE.ps1:6 char:1
+ import-module \\server\c$\SplitPipeline
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], FileLoadException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
If I try to copy it from the srv to the pc with:
Copy-Item -Path \\server\c$\SplitPipeline -Destination C:\windows\system32\WindowsPowerShell\v1.0\Modules -recurse -force
I get a access denied
any ideas¿?
thanks
The issue you're experiencing is that .NET assemblies can't be loaded from an untrusted UNC path, without special configuration. As you already discovered, the simplest solution is to copy the module to your local computer first.
To work around the "Access Denied" message, copy the module to your user directory, not the system-wide directory.
c:\users\<username>\Documents\WindowsPowerShell\Modules
You need to run PowerShell "as Administrator" in order to have permission to copy to the system folder, however it is generally recommended not to modify the default system directory. Instead, copy the module to your user folder (as above).