Uhh… is this thing on (still)?

Apparently blog posts don’t write themselves. Hmm. Whatever. Here’s a PowerShell script that will update all projects that are under source control in a directory (the directory is set inside the script):

# Directory of projects under source control
$projectsDir = 'C:\Dev\Third Party'

function Progress([string]$projectName, [system.action]$update)
{
    $activity = "Updating projects in " + $projectsDir + "..."
    $status = "Updating " + $projectName
    write-progress -activity $activity -status $status
    $update.Invoke()
}

# VCS update directory-command dictionary
$commands = new-object 'system.collections.generic.dictionary[string,system.action]'
$commands.Add(".svn", { svn update })
$commands.Add(".git", { git pull })
$commands.Add(".hg", { hg pull })

# Main
clear
cd $projectsDir
$dirs = ls | Where { $_.psIsContainer -eq $true }
foreach ($dir in $dirs)
{
    cd $dir
    $subdirs = ls -force
    
    foreach ($subdir in $subdirs)
    {
        if ($commands.ContainsKey($subdir.Name))
        {
            Progress $dir $commands[$subdir.Name]
        }
    }

    cd ..
}

You can add more $commands for your favorite VCS, if you wish. Note that this will only update one level of subdirectories (to stay compatible with Subversion… I think.)

Advertisements