copy folder to multiple machines

Hi all.

I try to find a solution so i can copy a folder contains some powershell modules from a share to multiple machines and to their modules folder under …system32, but only get path not found or access denied. I dont think the Destination line is correct :frowning:
Reason for this mass-copy is i wanna be able to run theese modules remotely on each server and get windows update status and install updates without to have login to every server

$cred = Get-Credential domain\admin
$pc = Get-Content G:\temp\srv.txt
$sourcePath = \\server1\PSWindowsUpdate
$destPath = \\$PC\c$\windows\system32\WindowsPowershell\v1.0\Modules
get-content $pc | copy-item -Source $sourcePath -Destination $destPath -Credential $cred -recurse

Throw some quotes in there!

$cred = Get-Credential domain\admin
$pc = Get-Content G:\temp\srv.txt
$sourcePath = "\\server1\PSWindowsUpdate"
$destPath = "\\$PC\c$\windows\system32\WindowsPowershell\v1.0\Modules"
get-content $pc | copy-item -Source $sourcePath -Destination $destPath -Credential $cred -recurse

$sourcePath and $destPath need to be strings

The recommended path for additional modules would be ‘C:\Program Files\WindowsPowerShell\Modules’. You should not copy them to your systems32 folder.

Hi thx for reply, now i get parameter -Source can not be found

“Copy-Item : A parameter cannot be found that matches parameter name ‘source’”

I probably should have looked at all of your code before fixing that 1 part and reposting it lol. -Source isn’t an accepted parameter. Use -Path instead. See below:

$cred = Get-Credential domain\admin
$pc = Get-Content G:\temp\srv.txt
$sourcePath = "\\server1\PSWindowsUpdate"
$destPath = "\\$PC\c$\windows\system32\WindowsPowershell\v1.0\Modules"
get-content $pc | copy-item -Path $sourcePath -Destination $destPath -Credential $cred -recurse

Copy-Item : Cannot retrieve the dynamic parameters for the cmdlet. The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform the operation again without specifying credentials.

Test without any -cred and get networkpath was not found, got this

CategoryInfo : ObjectNotFound: (C:\Windows\system32\server3:String) [Get-Content], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

it tries to copy to …\system32\destination-servername i have put in the srv.txt file

Get same error if i change the destination path to …\Program files\WindowsPowershell\Modules

Let’s remove the -Credential from Copy-Item. Instead, we’ll use New-PSSession to the computers in your list and copy with that. Try below:

$pc = Get-Content G:\temp\srv.txt
$sourcePath = "\\server1\PSWindowsUpdate"
$destPath = "\\$PC\c$\windows\system32\WindowsPowershell\v1.0\Modules"
$pc | foreach {
    $Session = New-PSSession -ComputerName "$_" -Credential (Get-Credential domain\admin);
    copy-item -Path $sourcePath -Destination $destPath -recurse -ToSession $Session -Force
    }

copy-item : The path ‘\server1 server2 server3\c$\Program Files\WindowsPowershell\Modules’ is not valid. Only absolute paths are supported on remote copy operatio

Yes i have tried …\system32\WindowsPowershell… get same error

Oh, haha. Here you go. Sorry about that.

$sourcePath = "\\server1\PSWindowsUpdate"
Get-Content G:\temp\srv.txt | foreach {
    $destPath = "\\$_\c$\windows\system32\WindowsPowershell\v1.0\Modules"
    $Session = New-PSSession -ComputerName "$_" -Credential (Get-Credential domain\admin);
    copy-item -Path $sourcePath -Destination $destPath -recurse -ToSession $Session -Force
    }

Sorry but same error…

copy-item : The path ‘\server2\c$\Program Files\WindowsPowerShell\Modules’ is not valid. Only absolute paths are supported on remote copy operations

Wow. Really not my best day, huh?

$sourcePath = "\\server1\PSWindowsUpdate"
$destPath = "C:\windows\system32\WindowsPowershell\v1.0\Modules"
Get-Content G:\temp\srv.txt | foreach {
    $Session = New-PSSession -ComputerName "$_" -Credential (Get-Credential domain\admin);
    copy-item -Path $sourcePath -Destination $destPath -recurse -ToSession $Session -Force
    }

Hmm seems that i have solve this by put in FQDN in $sourcepath \server1.domain.int\share and it works fine :frowning: