$VerbosePreference='continue' ###################################################################################### # # Servers you want to connect # ###################################################################################### $list_of_server_to_connect = @("BP-srvapp25","BP-srvapp26","BP-srvapp27") ###################################################################################### # # Command to type # ###################################################################################### #if password is required #$username = #$password = $Source_patch_folder = "C:\Users\pgeeraert_a\Desktop\2020.01.44.216\Roser Suite\RoserSuite_2020.01_Release_x64_216\" $Destination_patch_folder = "C:\Users\pgeeraert_a\Desktop" foreach($server in $list_of_server_to_connect){ #--Uncomment if password is required #$pw = convertto-securestring -AsPlainText -Force -String $password #$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$pw #$Session = New-PSSession -ComputerName $server -Credential $cred #-- #--Comment if password i srequired $Session = New-PSSession -ComputerName $server #-- write-output "connecting to $server" Copy-Item $Source_patch_folder -Destination $Destination_patch_folder -ToSession $Session -Recurse -Force write-output "Copy of $server done" }