One click to help you copy multiple files to multiple machines--powershell small script (with PS remote execution Command problem resolution)

Source: Internet
Author: User
Tags file copy set time

As a daemon ape, it is often necessary to copy a bunch of assemblies (DLLs) or applications (EXE) to multiple servers, implementing code logic updates for the program to test new functionality or change logic. Here is a self-implemented PowerShell script that allows you to replace the DLL or EXE on multiple Windows machines.

A Scripting uses

For easy copying of multiple files to multiple servers.

Two Scripting features

The main features of the script are as follows:

    • The file is filtered by the last modification time, and the files before the set time are not copied (the logical design originates from the Rebuild code and only replaces the newly created modified files );
    • Support multi-folder multi-file copy, folder and file path support wildcard character;
    • Through the configuration file, to support the replication of the file before stopping to the relevant Windows service or process, after copying the file will also be the Windows service startup ( logical design in order to avoid the destination of the existing files are involved in the process of the related processes caused by the failure of replication );
    • Supports replication of one operation to multiple servers;
    • The support command line specifies the computer parameter, ignoring multiple servers already set in the configuration file, processing only the server set up in the command line ( logical design in order to handle this situation: when replicating to a destination server fails, re-executing the operation to replicate a specific server after resolving the problem );
    • With configuration file control, you can recycle multiple times without having to enter cumbersome commands every time.

Three How to use

The command parameters are simple as follows, with a total of three available parameters:

    • path--configuration file path, required parameters;
    • credential--connection to the remote server authentication information, if not specified in the incoming, the box will be forced to specify;
    • computer--the server field that is set in the configuration file is ignored if the remote server address or first name that you want to manipulate is passed in.

The configuration file format example is as follows:

Where server fills the address of the remote server,service display name needs to stop the Windows service display name before the file is filled, process name fills in the names of the processes that need to be stopped, Item is the file or folder to be copied, the above parameters can have multiple nodes.

Last Write time stamp, all the modified time after the folder and files will be copied, only one.

Destination The folder path of the destination machine to be copied to, if it is not automatically created, there can only be one.

Four Effect

The source-side folders that need to be copied are as follows:

The Execute Command PowerShell window is as follows:

The effect of a destination server:

Five PowerShell Remote execution Command exception resolved

When using this script, you may encounter some problems, and the environment configuration, the specific situation and the solution is as follows:

· Running scripts is disabled on the system

, error when executing the command:

Workaround:

To run Windows PowerShell as an administrator, enter the following command to allow the script "Set-executionpolicy-executionpolicy unrestricted" to execute. If you do not want to set into unrestricted, refer to Set-executionpolicy.

· The Remove servers is not in the local server ' s WinRM trusterhosts list

, error when executing the command:

Workaround:

With the administrator running command Prompt, enter the following command "WinRM set winrm/config/client @{trustedhosts=" vm1,vm2 "}" to set the trust host.

· The user name or password is incorrect when creating new UNC folder

Although the password is guaranteed to be correct, the user name password is still reported incorrectly when creating the folder remotely or copying the file.

Workaround:

One is to manually access the UNC path directly, the user name password is saved in the system, and the second is to execute the following command "Cmdkey/add:targetname/user:username/pass:password", the user name password cache to the system.

· The remote servers do not has the WinRM service configured

The error is as follows:

Workaround:

On the destination machine (10.2.38.53), the Administrator runs command Prompt and enters the commands "WinRM quickconfig" to open the service:

Six Part of the Code

1.

2.

Note: The script is temporarily not perfect, complete a bit of functionality, there may be bugs, there is more space for optimization, such as the parallel execution of the copy command, support full command parameters, etc., may continue to update the optimization later.

Script: Http://files.cnblogs.com/files/lavender000/OneClickToReplaceMultipleFilesToMultipleServers.zip.

[Original articles, reproduced please indicate the source, for study purposes only, if there are errors please leave a message, such as like, please recommend, thank you support]

[Original: Http://www.cnblogs.com/lavender000/p/6958618.html, from forever-smoked]

One click to help you copy multiple files to multiple machines--powershell small script (with PS remote execution Command problem resolution)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.