Author Posts

January 8, 2018 at 5:12 pm

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 🙁
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

January 8, 2018 at 5:32 pm

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

January 8, 2018 at 5:40 pm

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

January 8, 2018 at 5:43 pm

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'"

January 8, 2018 at 5:49 pm

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

January 8, 2018 at 6:13 pm

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

January 8, 2018 at 6:21 pm

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
    }

January 8, 2018 at 6:35 pm

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

January 8, 2018 at 6:39 pm

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
    }

January 8, 2018 at 7:08 pm

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

January 8, 2018 at 7:09 pm

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
    }

January 9, 2018 at 6:18 pm

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