copy folder to multiple machines

This topic contains 11 replies, has 3 voices, and was last updated by  Roger Ohlsson 2 weeks ago.

  • Author
    Posts
  • #91057

    Roger Ohlsson
    Participant

    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
    
  • #91058

    Jeremy Corbello
    Participant

    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

  • #91061

    Olaf Soyk
    Participant

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

  • #91063

    Roger Ohlsson
    Participant

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

  • #91066

    Jeremy Corbello
    Participant

    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
  • #91067

    Roger Ohlsson
    Participant

    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

    • #91069

      Jeremy Corbello
      Participant

      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
          }
  • #91072

    Roger Ohlsson
    Participant

    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

    • #91073

      Jeremy Corbello
      Participant

      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
          }
  • #91076

    Roger Ohlsson
    Participant

    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

    • #91078

      Jeremy Corbello
      Participant

      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
          }
  • #91159

    Roger Ohlsson
    Participant

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

You must be logged in to reply to this topic.