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

Posted on 2012-08-20
Last Modified: 2012-08-20
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.
Question by:Tsz109
    LVL 9

    Accepted 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


    Author Comment

    Thanks a lot, i have the remote registry stuff already done.
    This got me started.
    LVL 9

    Expert Comment

    You're welcome :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
    This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
    This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now