-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange-mappings.ps1
50 lines (45 loc) · 1.7 KB
/
change-mappings.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
param(
$workspace = $(throw 'must specify a workspace'),
[string] $search = $(throw 'need a search string'),
[string] $replace = $(throw 'need a replace string')
)
[void] [reflection.assembly]::loadwithpartialname("Microsoft.TeamFoundation.VersionControl.Client")
if ($workspace -is [string])
{
$workspace = get-workspace $workspace
}
if ($workspace -isnot [microsoft.teamfoundation.versioncontrol.client.workspace])
{
throw 'Must specify workspace as an instance of Workspace or a string that works with get-workspace'
}
[microsoft.teamfoundation.versioncontrol.client.workingfolder[]] $newMappings = @()
foreach ($existingMapping in $workspace.Folders)
{
trap { 'Failure during creation of new mapping - check your search and replace strings'; break; }
$newMapping = new-object 'microsoft.teamfoundation.versioncontrol.client.workingfolder' `
($existingMapping.ServerItem -replace $search,$replace), `
($existingMapping.LocalItem -replace $search,$replace), `
$existingMapping.Type
if ($existingMapping -ne $newMapping)
{
write-host ('Changing {0}={1} to {2}={3} [{4}]' -f
$existingMapping.ServerItem, $existingMapping.LocalItem,
$newMapping.ServerItem, $newMapping.LocalItem, $newMapping.Type)
$needToUpdate=$true
}
else
{
write-host ('Keeping {0}={1} [{2}]' -f
$existingMapping.ServerItem, $existingMapping.LocalItem, $existingMapping.Type)
}
$newMappings += $newMapping
}
if ($needToUpdate)
{
$workspace.Update($workspace.Name, $workspace.Comment, $newMappings)
write-host "Successfully updated mappings for workspace $($workspace.DisplayName)"
}
else
{
write-host 'No mappings changed'
}