forked from StingyJack/Vs-Utility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFind-Shelveset.ps1
87 lines (70 loc) · 3.29 KB
/
Find-Shelveset.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<#
.SYNOPSIS
Finds shelveset based on the paramters given.
.NOTE
This is needed until VS Team Explorer can list all my shelvesets. VS TE currently
requires a name to filter, and I don't remember the names of some shelvesets. This
gives me a nice list to go through.
#>
function Find-Shelveset
{
[CmdletBinding()]
Param(
[string] $UserName,
[switch] $IncludeGCI,
[switch] $IncludeAutoShelve,
[switch] $IncludeCodeReview
)
$existingProgressPreference = $Global:ProgressPreference
$Global:ProgressPreference = 'SilentlyContinue'
Write-Verbose "Global progress preference was '$existingProgressPreference' and is now 'SilentlyContinue'"
try
{
$projectCollectionUrls = Get-TfsTeamProjectCollectionUrlList
$allShelveSets = @()
Write-Verbose "Finding shelvesets for $UserName on $($projectCollectionUrls.Count) project collections"
foreach ($projectCollectionUrl in $projectCollectionUrls)
{
Write-Verbose "Using project collection url $projectCollectionUrl"
$allDone = $false
$currentSkipValue = 0
while ($allDone -eq $false) {
$url = "$projectCollectionUrl/_apis/tfvc/shelvesets?owner=$UserName&`$skip=$currentSkipValue"
$resp = Invoke-WebRequest -Uri $url -UseDefaultCredentials
$shelveSetBlock = $resp.Content | ConvertFrom-Json
foreach ($shelveSet in $shelveSetBlock.value)
{
$shelveSetName = $shelveset.name
if ($shelveSetName.StartsWith("AutoShelve", [System.StringComparison]::OrdinalIgnoreCase))
{
if ($IncludeAutoShelve.IsPresent -eq $false) { continue }
}
if ($shelveSetName.StartsWith("Gated", [System.StringComparison]::OrdinalIgnoreCase))
{
if ($IncludeGCI.IsPresent -eq $false) { continue }
}
if ($shelveSetName.StartsWith("CodeReview", [System.StringComparison]::OrdinalIgnoreCase))
{
if ($IncludeCodeReview.IsPresent -eq $false) { continue }
}
if ($allShelveSets -notcontains $shelveSetName)
{
$shelveSet | Add-Member -MemberType NoteProperty -Name TeamProjectCollectionUrl -Value $projectCollectionUrl
$allShelveSets += $shelveSet
}
}
$currentSkipValue += 100
if ($shelveSetBlock.count -lt 100)
{
$allDone = $true
}
} #end iterating the current project collection shelfset list
} #next project collection Url
$allShelveSets | Sort-Object -Property TeamProjectCollectionUrl,createdDate -Descending | Select-Object -Property TeamProjectCollectionUrl,name,createddate | Format-Table
}
finally
{
$Global:ProgressPreference = $existingProgressPreference
Write-Verbose "Global progress preference has been set back to '$existingProgressPreference'"
}
}