Created
June 13, 2012 06:01
-
-
Save jstangroome/2922148 to your computer and use it in GitHub Desktop.
PowerShell script to perform a simple check-in of a Visual SourceSafe project's latest files to Team Foundation Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] | |
[ValidatePattern('^(\\\\|[a-z]\:)')] # \\share or drive: | |
[string] | |
$VssRepositoryPath, | |
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] | |
[ValidatePattern('^\$/')] # $/something | |
[string] | |
$VssServerPath, | |
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] | |
[ValidatePattern('^https?://')] # http://something | |
[string] | |
$TfsCollectionUri, | |
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] | |
[ValidatePattern('^\$/')] # $/something | |
[string] | |
$TfsServerPath | |
) | |
begin { | |
$script:ErrorActionPreference = 'Stop' | |
Set-StrictMode -Version Latest | |
# check for the VSS command line tool | |
$ssexe = 'C:\Program Files (x86)\Microsoft Visual SourceSafe\ss.exe' | |
if (-not (Test-Path -Path $ssexe)) { | |
throw "SourceSafe command line tool not found at expected location '$ssexe'" | |
} | |
# check for the TFS command line tool | |
$tfexe = 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe' | |
if (-not (Test-Path -Path $tfexe)) { | |
throw "TFS command line tool not found at expected location '$tfexe'" | |
} | |
# check for TFS Power Tool command line utility | |
$tfptexe = 'C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools\TFPT.EXE' | |
if (-not (Test-Path -Path $tfptexe)) { | |
Write-Warning "TFS Power Tool command line utility not found at expected location '$tfptexe'.`nVSS solution bindings will not automatically be converted to TFS bindings." | |
$tfptexe = $null | |
} | |
$LogPath = [IO.Path]::GetTempFileName() | |
"Logging to '$LogPath'." | |
} | |
process { | |
$WorkingPath = 'c:\vsstotfs' | |
"Preparing local path '$WorkingPath'." | |
if (Test-Path -Path $WorkingPath -PathType Container) { | |
Get-ChildItem -Path $WorkingPath -Force | | |
Remove-Item -Recurse -Force | |
} else { | |
New-Item -Path $WorkingPath -ItemType Container | Out-Null | |
} | |
Push-Location $WorkingPath | |
try { | |
"Connecting to VSS repository '$VssRepositoryPath'." | |
$Env:SSDIR = $VssRepositoryPath | |
& $ssexe project >>$LogPath | |
if (-not $?) { | |
Write-Error -EA Continue -Message "ss.exe project failed: $LastExitCode" | |
return | |
} | |
"Mapping VSS server path '$VssServerPath' to local path '$WorkingPath'." | |
& $ssexe workfold $VssServerPath $WorkingPath >>$LogPath | |
if (-not $?) { | |
Write-Error -EA Continue -Message "ss.exe workfold failed: $LastExitCode" | |
return | |
} | |
'Getting files from VSS... (this may take a long time)' | |
# recursively (-R) and writeable (-W) | |
& $ssexe get $VssServerPath -R -W >>$LogPath | |
if (-not $?) { | |
Write-Error -EA Continue -Message "ss.exe get failed: $LastExitCode" | |
return | |
} | |
#TODO optionally create tfs project (slow, most likely easier to pre-create) | |
$TfsWorkspaceName = 'vsstotfs' | |
# clean up workspace if it failed last time | |
& $tfexe workspace /delete $TfsWorkspaceName /noprompt >>$LogPath | |
# its ok if the workspace delete fails | |
"Creating TFS workspace for collection '$TfsCollectionUri'." | |
& $tfexe workspace /new /noprompt $TfsWorkspaceName /collection:$TfsCollectionUri >>$LogPath | |
if (-not $?) { | |
Write-Error -EA Continue -Message "tf.exe workspace /new failed: $LastExitCode" | |
return | |
} | |
"Mapping TFS server path '$TfsServerPath' to local path '$WorkingPath'." | |
& $tfexe workfold /map $TfsServerPath $WorkingPath >>$LogPath | |
if (-not $?) { | |
Write-Error -EA Continue -Message "tf.exe workfold failed: $LastExitCode" | |
return | |
} | |
'Adding local files as pending changes to TFS.' | |
& $tfexe add *.* /noprompt /recursive >>$LogPath | |
if (-not $?) { | |
Write-Error -EA Continue -Message "tf.exe add failed: $LastExitCode" | |
return | |
} | |
'Committing pending changes to TFS.' | |
& $tfexe checkin *.* /recursive /comment:vsstotfs /noprompt /override:vsstotfs /bypass /force >>$LogPath | |
if (-not $?) { | |
Write-Error -EA Continue -Message "tf.exe checkin failed: $LastExitCode" | |
return | |
} | |
if ($tfptexe) { | |
'Converting VSS solution bindings to TFS bindings.' | |
& $tfptexe bind /convert /recursive | |
if ($LastExitCode -eq 100 <# tfpt failure exit code #>) { | |
Write-Warning 'tfpt.exe bind failed.' | |
} | |
'Committing pending bindings changes to TFS.' | |
& $tfexe checkin *.* /recursive /comment:vsstotfs-bindings /noprompt /override:vsstotfs /bypass /force >>$LogPath | |
if (-not $?) { | |
Write-Warning -EA Continue -Message "tf.exe checkin failed to commit bindings changes: $LastExitCode" | |
} | |
} | |
'Removing TFS workspace.' | |
& $tfexe workspace /delete $TfsWorkspaceName /noprompt >>$LogPath | |
} finally { | |
Pop-Location | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment