<# .SYNOPSIS This Powershell script will create a Master and Slave Repos .DESCRIPTION This Powershell script will create a Master and Slave Repos It will Create the Master on the current machine Copy Global Hooks into the new Repo Create Slaves Copy Global Hooks into the new slaves .PARAMETER Repo Name of the Repo to create .PARAMETER Slaves A list of Slave servers that are a part of the subversion network These will be reconfigured to communicate with the new master If none are provided then only the Master Repo will be created .EXAMPLE CreateRepo.ps1 -Slave auawssvn001,cloudasvn03 .NOTES Uses a number of cmdlets provided by VisualSVN. #> # Param ( [ parameter (Mandatory=$true, HelpMessage="Enter the name of the new Repository")] [string] $Repo, [ parameter () ] [string[]] $Slaves ) # # Get information on the current SVN server # function GetSvnInfo() { $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Service Return $RepoData } # # Get information on a named repo function GetRepoInfo( $repoName ) { $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository | Where { $_.Name -eq $repoName } Return $RepoData } # # Get information on a named repo on the named Computer function GetRemoteRepoInfo( $repoName, $ComputerName ) { $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository -ComputerName $ComputerName | Where { $_.Name -eq $repoName } Return $RepoData } # # Convert Absolute Path to UNC on a named computer # Function AbsToUnc( $ComputerName, $absPath ) { return '\\' + $ComputerName + '\' + $absPath.Replace(":","$") } # # Determine the root of the Repositores $SvnInfo = GetSvnInfo if ($SvnInfo -eq $null) { Write-Error 'Cannot get VisualSVN info' Exit } # Validate the Repo Root $repoRoot = $SvnInfo.RepositoriesRoot If (!(Test-Path $repoRoot)) { Write-Error 'RepositoriesRoot - Does not exist' Exit } # # Ensure the named repo does not exist # $RepoData = Get-SvnRepository -Name $Repo -ErrorAction SilentlyContinue If ( $RepoData ) { Write-Host "Repository ($Repo) already exists" Return } # # Create the Master Repo # Write-Host 'Creating Master Repository' $RepoData = New-SvnRepository -Name $Repo -Type VdfsMaster # # Copy in global hooks # Write-Host 'Transfer Global Hooks' $RepoInfo = GetRepoInfo $Repo $HookSrc = $repoRoot $hookPath = $RepoInfo.Path + '/hooks' $HookFileCount = 0 Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object { $srcFile = $_.Name Copy-Item $_.FullName -Destination $hookPath $HookFileCount++ } Write-Host "Hook Files Copied: $HookFileCount" # # Create Slaves too # If ( $Slaves ) { #Write-Host $Slaves # # Add Slave list to the Master # $Replicators = $Slaves | ForEach-Object { $_ + '$' } Set-SvnRepositoryReplication $Repo -Replicators $Replicators -Enabled:$true $Slaves | ForEach-Object { Write-Host "Creating Slave Repository $_" $NewRepo = New-SvnRepository $Repo -MasterServer $env:COMPUTERNAME -Type VdfsSlave -CimSession $_ # # Copy Hooks to the Slave # # Get target Repo Information # Want the path to the hooks directory # $targetRepo = GetRemoteRepoInfo $Repo $_ $hookPath = $targetRepo.Path + '\hooks' $hookPathUnc = AbsToUnc $_ $hookPath # # Copy files to Remote Computer # #Write-Host "Hooks Found", $hookPathUnc $HookFileCount = 0 Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object { $srcFile = $_.Name Copy-Item $_.FullName -Destination $hookPathUnc $HookFileCount++ } Write-Host "Hook Files Copied: $HookFileCount" } }