Disclaimer
This is my personal blog. The opinions and views I express are my own. The information I provide is on an as-is basis. I make no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this blog and will not be liable for any errors, omissions, or delays in this information or any losses, injuries or damages arising from its use.

Copy a folder and files to multiple computers (Powershell)

** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK **

I used this script to copy a new desktop background image to about 100 computers recently.

Usage:
1. You will need to create a folder on your computer (eg c:\script).
2. Copy the script to the folder in Step 1 and name it something (eg copyFiles.ps1).
3. Edit the script to change the $computers and $source variable to match your folder structure.
4. Open a Powershell window
5. Navigate to that folder you created.
6. To run the script type .\copyFiles.ps1

 

<#
	** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK **	

    .SYNOPSIS
	    Create new mailboxes in Exchange 2010 and the corresponding user in Active Directory.

	.DESCRIPTION
	    Copy a directory and all files within the directory to multiple computers.

    .REQUIREMENTS
        1.	The appropriate rights to ping and copy on the remote machine.
		2.  A computers.txt file with a list of computer names

    .NOTES
        Tested with Windows 7, Windows Vista, Windows Server 2003, Windows Server 2K8 and 2K8 R2

	.AUTHOR
		David Hall | https://www.signalwarrant.com/

	.LINK
		https://www.signalwarrant.com/2012/10/04/copy-a-folder-and-files-to-multiple-computers-powershell/

#>

# This is the file that contains the list of computers you want 
# to copy the folder and files to. Change this path IAW your folder structure.
$computers = gc "C:\scripts\computers.txt"

# This is the directory you want to copy to the computer (IE. c:\folder_to_be_copied)
$source = "c:\files"

# On the desination computer, where do you want the folder to be copied?
$dest = "c$"

foreach ($computer in $computers) {
    if (test-Connection -Cn $computer -quiet) {
        Copy-Item $source -Destination \\$computer\$dest -Recurse
    } else {
        "$computer is not online"
    }

}

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.