Skip to content

Instantly share code, notes, and snippets.

@ipanin
Forked from baywet/gittfsmigrationcleanup.ps1
Last active March 28, 2020 19:53
Show Gist options
  • Save ipanin/bea4ec41dac71010b70dbd9adbfbd877 to your computer and use it in GitHub Desktop.
Save ipanin/bea4ec41dac71010b70dbd9adbfbd877 to your computer and use it in GitHub Desktop.
small powershell script which allows you to quickly clean your repo during the migration
#Requires -Version 3.0
param([string]$targetPath)
Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
if (Test-Path variable:global:psISE) { $scriptPath = Split-Path $psise.CurrentFile.FullPath; }
else { $scriptPath = $PSScriptRoot; }
if ($targetPath -eq "") { $targetPath = $scriptPath }
$targetSearchPath = $targetPath + "\*"
Remove-Item $targetSearchPath -Recurse -include *.vspscc,*.vssscc -Verbose
$slnRegexPattern = 'GlobalSection\(TeamFoundationVersionControl\)[:\w\d\s\\.=\/{}-]*EndGlobalSection'
$slnFiles = Get-ChildItem -Path $targetSearchPath -Recurse -Filter *.sln
foreach($slnFile in $slnFiles)
{
$content = Get-Content $slnFile.FullName -Raw
if($content -match $slnRegexPattern)
{
($content -replace $slnRegexPattern, '') | Out-File -FilePath $slnFile.FullName -Verbose -Encoding utf8;
}
}
$projRegexPattern = "\s+<Scc.*<\/Scc\w*>"
$projFiles = Get-ChildItem -Path $targetSearchPath -Recurse -include *.csproj,*.sqlproj
foreach($projFile in $projFiles)
{
$content = Get-Content $projFile.FullName -Raw
if($content -match $projRegexPattern)
{
Write-Host "Cleaning $($projFile.Name)"
($content -replace $projRegexPattern, '') | Out-File -FilePath $projFile.FullName -Encoding utf8;
}
}
Write-Host "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment