[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 870
  • Last Modified:

Powershell help : Making a script that sends a folder to all servers

Hello everyone;
like many others on here I am trying to get into powershell.
The script I am trying to write is where I copy a folder from 1 main server out to every server in a domain. (overwrite the folder if it is already there).

input a registry key to have the BGinfo to start with every user.

so far i have this.

if (Test-Path "C:\support\bginfo")
{ remove-item -path "C:\support\bginfo" -Recurse }

copy-item \\XXXXXXXXXXX\_Server_Support\support -Destination C:\support -Recurse

Set-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -name "BgInfo" -value  "C:\support\bginfo\Bginfo.exe C:\support\bginfo\standard.bgi /TIMER:0 /NOLICPROMPT"

I can run this on a local server but how do I script this so it goes out every computer account in a domain? and output a file on which servers it fails on?

The environment is all server 2003 and 2008 r2.

Please I need some help on this. If it is easier I can just tell it to read from a list of computer names. I can pull the computer accounts from AD myself.
  • 2
1 Solution
OK this ought to help you get started, please bear in mind it's not fully featured, but I'm sure you can start to see how you can progress from here, I don't have time to write every aspect of this script for you myself.

Tested in my lab, you could feed in your server list differently to how I did, I just wanted something quick and easy.

I've not included remote registry stuff here, that is a little more complicated, and quite frankly I don't want to be responsible for breaking your registry :D

$ServerList = @()
$ServerList += "HIPPOSDC01"
$ServerList += "HIPPOSMBX01"
$ServerList += "HIPPOSMBX02"
$ServerList += "HIPPOSCAS01"
$ServerList += "HIPPOSHT01"

$FolderToCopy = "\\HIPPOSDC01\Share\CopyMe"

foreach ($Server in $ServerList)
	#Echo back current server
	Write-Host "Processing Server $Server..." -ForeGroundColor "Yellow"
	#Remove Path if it exists on remote server
	$UNCPath = "\\$Server\C$\Support\bginfo"
	Write-Host "Checking/Removing UNC Path $UNCPath"
	if (Test-Path $UNCPath)
		Remove-Item -path $UNCPath -Recurse -Force
	#Copy folder content from source to destination
	Write-Host "Copying folder $FolderToCopy to destination $UNCPath"
	Copy-Item $FolderToCopy -Destination $UNCPath -Recurse -Force

Open in new window

Tsz109Author Commented:
Thanks a lot, i have the remote registry stuff already done.
This got me started.
You're welcome :)

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now