I am trying to copy a file to multiple servers using powershell.
$FullPath = $MyInvocation.MyCommand.Path$Scriptpath = Split-Path -Path $FullPath -Parentcd $Scriptpath$servers= '.\servers.txt'$Source = '.\TraceConsolidator.exe.config'$outfile = ".\ViewResult.log"$Destination = 'Program Files\ndwill mynde\Sym\SyM_configMgmt'#$computers = Get-Content $servers[string[]]$Computers = Get-Content "$servers"If(Test-Path $outfile) {Remove-Item -Path $outfile -Force}ForEach($computer in $Computers){"Trying to connect to $computer""Trying to connect to $computer " >> $outfileif(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet)){"Problem in connecting to $computer""Problem in connecting to $computer " >> $outfile"***********************************">> $outfile}else{"Connected to $computer""Connected to $computer " >> $outfileCopy-Item $Source -Destination '\\$computer\C$\Program Files\ndwill mynde\Sym\SyM_configMgmt' -Forceif (Test-Path "\\$computer\C$\Program Files\ndwill mynde\Sym\SyM_configMgmt\TraceConsolidator.exe.config") {write-host "copying the file to the C:\$Destination in $computer is successful""copied the file to the C:\$Destination in $computer " >> $outfile"**************************************************">> $outfile}else{write-host "copying the file to the C:\$Destination in $computer is not successful" "copying the file to the C:\$Destination in $computer is not successful " >> $outfile "***********************************">> $outfile}}}
But the script says it is connected to the computer and tbe says as below
Copy-Item : Could not find a part of the path '\\171.128.6.10\C$\Program Files\ndwill mynde\Sym\SyM_configMgmt. This works fine if there is no space in the destination path.
Can you help me with what I am missing here.
Powershell
Last Comment
Michael Kimmel
8/22/2022 - Mon
Qlemo
The message cannot be a result of above script. You are using
with the destination path enclosed in single quotes, and that prevents resolution of any variable. It tries to copy to that literal path as provided, and will not succeed.
Leaving that aside, assuming you made an error when posting here only (as the error message tells), the only other reason is that the remote path does not exist (yet). Spaces in the path are no reason.
Did you try a
dir '\\171.128.6.10\C$\Program Files\ndwill mynde\Sym\SyM_configMgmt'
for testing? If you get an error, start with '\\171.128.6.10\C$' and drill down the path until you get an error.
Errors with "Program Files" often originate from x86 software on x64 OS. in which case you need to use "Program Files (x86)".
Open in new window
with the destination path enclosed in single quotes, and that prevents resolution of any variable. It tries to copy to that literal path as provided, and will not succeed.Leaving that aside, assuming you made an error when posting here only (as the error message tells), the only other reason is that the remote path does not exist (yet). Spaces in the path are no reason.
Did you try a
Open in new window
for testing? If you get an error, start with '\\171.128.6.10\C$' and drill down the path until you get an error.Errors with "Program Files" often originate from x86 software on x64 OS. in which case you need to use "Program Files (x86)".