PowerShell: Copying Latest Files to multiple servers

By | 8 June, 2015

Problem: I have a source folders which consisted of multiple directory’s (builds from TFS). I wanted to copy the latest folder (Based on LastWriteTime) to several servers.

Answer: use-powershell (what else 😉  )

$serverlist = @("\\server1\d$\install\software","\\server2\d$\install\software", "\\server3\d$\install\software")
$LatestBuild = (get-childitem D:\sourcedirectory | Sort-Object LastWriteTime -Descending | select-object -first 1).FullName
$serverlist | Foreach {Copy-Item $LatestBuild -Recurse -Destination $_}

Leave a Reply

Your email address will not be published. Required fields are marked *