Link to home
Start Free TrialLog in
Avatar of Chris Cadey
Chris CadeyFlag for United Kingdom of Great Britain and Northern Ireland

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 :

$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

Open in new window


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

Open in new window

Avatar of Alex
Alex
Flag of United Kingdom of Great Britain and Northern Ireland image

I don't understand why you're putting in the username and password, your better option would be to use a scheduled task and then implement the username from there.

Thus, only leaving you with

Copy-item -FromSession $Session -Path "D:\xxxxx\Apps" -Destination "C:\xxxxx" -Recurse

Open in new window


Or do a run as on your powershell application.

Regards

Alex
Oh sorry

Do

$Computers = Get-content c:\temp\computers.txt

Foreach ($Computer in $Computer){Copy-item -Path "D:\xxxxx\Apps" -Destination "\\$($Computer)\c$\xxxxx" -Recurse}

Open in new window


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
Avatar of yo_bee
yo_bee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris Cadey

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?
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
OK tried it with Robocopy and its worked a treat. many thanks
Robcopy is the $h!t in my world.