Scripts

Simple File Copy Script

Very often I have to copy files around during a deployment. So to make it simple I have a script that will do that for me. You can add roles (I have commented out edge since that is not usually domain joined.

$Source = “C:\Source”

$currenthost = (Get-WmiObject win32_computersystem).DNSHostName+”.”+(Get-WmiObject win32_computersystem).Domain

$filestocopy = get-childitem $source | %{$_.FullName}

#Function To copy files

function CopyFiles {

param ($server)

$Destination = “\\” + $server + “\c$\source\”

$currenthost

$server

$destination

if (!($currenthost -like $server)) {

Remove-Item $Destination -Recurse -Force -Confirm:$false

new-item -Path $Destination -ItemType directory -Force

$filestocopy | % {copy-item -Destination $destination -path $filestocopy}

}

}

foreach ($server in get-cspool | ?{$_.services -match “MediationServer:”} | %{$_.Computers} ) {

Copyfiles $server

}

<#foreach ($server in get-cspool | ?{$_.services -match “EdgeServer:”} | %{$_.Computers} ) {

Copyfiles $server

}

#>

foreach ($server in get-cspool | ?{$_.services -match “Registrar:”} | %{$_.Computers} ) {

Copyfiles $server

}

Leave a Reply

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