Select Page
This entry has been published on 2014-05-28 and may be out of date.

Last Updated on 2014-05-28.

Using multiple Mediacenter stations running OpenElec / XBMC, there are only one or two files you need to copy from another machine or a central store manually to set substitution and database paths.

If you do not want to copy everything manually after every little modification, you can use the following simple Powershell script e.g. on a Windows server, scheduled every hour, to distribute the files to your Mediacenter systems’ SMB share. It copies every file (beginning with “From:”) to every destination (“To:”).

$froms = Get-Content $PSScriptRootdistributeFilesConfig.txt | where { $_.ToString().StartsWith("From:") }
$tos = Get-Content $PSScriptRootdistributeFilesConfig.txt | where { $_.ToString().StartsWith("To:") }
 
foreach($fromfile in $froms)
{
    $fromfile = $fromfile.Replace("From:", "").Trim();
 
    foreach($todir in $tos)
    {
        $todir = $todir.Replace("To:", "").Trim();
                        
        $computername = $todir.Split("\")[2];

        if (Test-Connection $computername -Quiet -Count 1)
        {
            if (Test-Path $todir)
            {
                echo "Copying " $fromfile " to " $todir;
                Copy-Item -Path $fromfile -Destination $todir;
            }
            else
            {
                echo $todir "is not valid";
            }
        }
        else
        {
            echo "Host " $todir "is not online";
        }


        echo "";
    }
}

Give the PS file a name like distributeFiles.ps1.

In the same directory of the script create a file distributeFilesConfig.txt. Here is an example of some content:

From:\mediaxbmc_stuffuserdataadvancedsettings.xml
To:.1.0.90UserData
To:.1.0.91UserData
To:.1.0.92UserData
To:.1.0.93UserData