Chris Cadey
asked on
Copy-item script not working properly
having problems getting my script to work. it fundamentally needs to copy an app folder from the server and drop it to the workstations, so I'm using a script to achieve this. however its throwing up multiple errors of the same type, weirdly some files copy ok.
Heres the script :
Heres the errors :
Heres the script :
$pw = ConvertTo-SecureString -AsPlainText -Force -String xxxxxx
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "xxxx\xxxx",$pw
$Session = New-PSSession -ComputerName "server" -Credential $cred
Copy-item -FromSession $Session -Path "D:\xxxxx\Apps" -Destination "C:\xxxxx" -Recurse
Heres the errors :
Copy-item : Method invocation failed because [System.IO.MemoryStream] does not contain a method named 'new'.
At line:4 char:1
+ Copy-item -FromSession $Session -Path "D:\xxxxx\Apps" -Destination ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], RuntimeException
+ FullyQualifiedErrorId : System.Management.Automation.RuntimeException,WriteException
Oh sorry
Do
If you let me know where you're getting the destination computer, I.E Active directory or something, I can get it from there.
Do
$Computers = Get-content c:\temp\computers.txt
Foreach ($Computer in $Computer){Copy-item -Path "D:\xxxxx\Apps" -Destination "\\$($Computer)\c$\xxxxx" -Recurse}
If you let me know where you're getting the destination computer, I.E Active directory or something, I can get it from there.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm launching the PowerShell script from our software deployment platform. The software determines the workstations to install on, whether its all of them or certain selected ones or even just one. the script remains the same.
can robocopy be used from within powershell?
can robocopy be used from within powershell?
Yes:
Here is a script from the MS Gallery that will help.
In Powershell you can run other commands and use variables from powerhsell cmdlets to be passed to the command..
https://gallery.technet.microsoft.com/scriptcenter/Robocoy-Files-to-Remote-bdfc5154
Here is a script from the MS Gallery that will help.
In Powershell you can run other commands and use variables from powerhsell cmdlets to be passed to the command..
https://gallery.technet.microsoft.com/scriptcenter/Robocoy-Files-to-Remote-bdfc5154
ASKER
OK tried it with Robocopy and its worked a treat. many thanks
Robcopy is the $h!t in my world.
Thus, only leaving you with
Open in new window
Or do a run as on your powershell application.
Regards
Alex