Rev 5287 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<#.SYNOPSISThis Powershell script will update the repo-Wide hook in all the Repos.DESCRIPTIONThis Powershell script update the repo-Wide hook in all the Repos onthe current machine and the named serversIt willLocate the Repository RootCopy *.cmd file from the root into each Repo SubdirUnless the special hooks/specialhooks file existsProcess each Named serverCopy the global files to the serverCopy the global files to each (non-special) repo on the server.PARAMETER ServersA list of Slave servers that are a part of the subversion networkThe hooks will be propergated to all the servers and all the Repos on all the Servers.EXAMPLEUpdateHooks.ps1 -Servers auawsasvn001,cloudasvn03.NOTESUses a number of cmdlets provided by VisualSVN.#>#Param([ parameter () ][string[]] $Servers)## Get information on a named repofunction 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 Computerfunction GetRemoteRepoInfo( $repoName, $ComputerName ){$repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository -ComputerName $ComputerName | Where { $_.Name -eq $repoName }Return $RepoData}## Get information on the current SVN server#function GetSvnInfo(){$repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_ServiceReturn $RepoData}## Get information on the SVN server on the named Computer#function GetRemoteSvnInfo($ComputerName){$repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Service -ComputerName $ComputerNameReturn $RepoData}## Convert Absolute Path to UNC on a named computer#Function AbsToUnc( $ComputerName, $absPath ){return '\\' + $ComputerName + '\' + $absPath.Replace(":","$")}## Test a server to see if it exists#Function CheckServer( $ComputerName){$testSession = New-CimSession $ComputerName -ErrorAction IgnoreIf($testSession -eq $null){#Write-Error "The named computer ($ComputerName) does not exist" -Category InvalidArgumentReturn $false}Remove-CimSession $testSessionReturn $true}## Determine the root of the Repositores$SvnInfo = GetSvnInfoif ($SvnInfo -eq $null){Write-Error 'Cannot get VisualSVN info'Exit}# Validate the Repo Root$repoRoot = $SvnInfo.RepositoriesRootIf (!(Test-Path $repoRoot)){Write-Error 'RepositoriesRoot - Does not exist'Exit}## Process each Repo$HookSrc = $repoRootGet-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository | Sort-Object Name | ForEach-Object {$hookPath = $_.Path + '/hooks'$repoName = $_.NameIf (!(Test-Path ($hookPath + '/specialhooks'))){$HookFileCount = 0Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {$srcFile = $_.NameCopy-Item $_.FullName -Destination $hookPath$HookFileCount++}Write-Host ("{0,20} : {1}" -f $repoName, "Hooks copied: $HookFileCount")}else{Write-Host ("{0,20} : {1}" -f $repoName, "SPECIAL - No hooks copied")}}## Process named servers#If ($Servers){$Servers | ForEach-Object{$Server = $_Write-Host 'Server:' $ServerIf ( ! (CheckServer $Server)){Write-Host -ForegroundColor Red "The server ($Server) does not exist"Return}##$remoteServer = GetRemoteSvnInfo ($Server)$remoteRepoBase = AbsToUnc $Server $remoteServer.RepositoriesRoot$HookFileCount = 0Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {$srcFile = $_.NameCopy-Item $_.FullName -Destination $remoteRepoBase$HookFileCount++}Write-Host ("{0,20}, {1,20} : {2}" -f $Server, 'Global Hooks', "Hooks copied: $HookFileCount")## Update all Repos on the Server#Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository -ComputerName $Server | Sort-Object Name | ForEach-Object {$hookPath = AbsToUnc $Server ($_.Path + '\hooks')$repoName = $_.NameIf (!(Test-Path ($hookPath + '\specialhooks'))){$HookFileCount = 0Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {$srcFile = $_.NameCopy-Item $_.FullName -Destination $hookPath$HookFileCount++}Write-Host ("{0,20}, {1,20} : {2}" -f $Server, $repoName, "Hooks copied: $HookFileCount")}else{Write-Host ("{0,20}, {1,20} : {2}" -f $Server, $repoName, "SPECIAL - No hooks copied")}}}}