troubleshooting Question

copy files to remote computers using powershell

Avatar of karkou12
karkou12 asked on
Powershell
3 Comments1 Solution1696 ViewsLast Modified:
Hi Experts,

I am trying to copy a file to multiple servers using powershell.

$FullPath = $MyInvocation.MyCommand.Path
$Scriptpath = Split-Path -Path $FullPath -Parent
cd $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 " >> $outfile

if(!(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 " >> $outfile


Copy-Item $Source -Destination '\\$computer\C$\Program Files\ndwill mynde\Sym\SyM_configMgmt' -Force
if (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.
ASKER CERTIFIED SOLUTION
Jason Crawford
Transport Ninja

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros