-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-tfsclient-policies.ps1
70 lines (65 loc) · 2.98 KB
/
check-tfsclient-policies.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
# load a couple of assemblies we expect to need
[void][reflection.assembly]::loadwithpartialname('microsoft.teamfoundation.versioncontrol.client')
[void][reflection.assembly]::loadwithpartialname('system.windows.forms')
function check_assemblies_at_path([string] $registryPath)
{
if (!(test-path $registryPath))
{
write-debug "skipping registry path which does not exist: $registryPath"
return
}
$policiesKey = get-item $registryPath
$policyAssemblyNames = $policiesKey.GetValueNames()
foreach ($policyAssemblyName in $policyAssemblyNames)
{
$policyAssemblyPath = $policiesKey.GetValue($policyAssemblyName)
if ($policyAssemblyPath)
{
$pathBaseName = $policyAssemblyPath -replace '.*\\(.*).dll','$1'
if ($pathBaseName -ne $policyAssemblyName)
{
write-warning ('Registry value {0} should be changed to match assembly base name {1}' -f $policyAssemblyName, $pathBaseName)
}
if (!(test-path $policyAssemblyPath))
{
write-warning "File location specified for $policyAssemblyName is missing: $policyAssemblyPath"
continue
}
$policyAsm = [reflection.assembly]::LoadFrom($policyAssemblyPath)
}
else
{
$policyAsm = [reflection.assembly]::Load($policyAssemblyName)
}
$policyTypes = @($policyAsm.gettypes() |
?{ [microsoft.teamfoundation.versioncontrol.client.ipolicydefinition].isassignablefrom($_) -and
[microsoft.teamfoundation.versioncontrol.client.ipolicyevaluation].isassignablefrom($_) })
write-debug ('Found {0} policy type(s) in assembly {1}: {2}' -f $policyTypes.Length, $policyAssemblyName, $policyTypes)
foreach ($policyType in $policyTypes)
{
write-debug "Examining $policyType"
if ([attribute]::getcustomattribute($policyType, [SerializableAttribute]) -eq $null)
{
write-warning "Policy type $policyType fails the check for [Serializable]"
}
if (!$policyType.IsClass)
{
write-warning "Policy type $policyType fails the check for being a class"
}
if ($policyType.IsAbstract)
{
write-warning "Policy type $policyType fails the check for not being abstract"
}
if (!$policyType.IsPublic)
{
write-warning "Policy type $policyType fails the check for being public"
}
if ($policyType.GetConstructor(@()) -eq $null)
{
write-warning "Policy type $policyType fails the check for having a zero-arg constructor"
}
}
}
}
check_assemblies_at_path('HKLM:\SOFTWARE\Microsoft\VisualStudio\8.0\TeamFoundation\SourceControl\Checkin Policies')
check_assemblies_at_path('HKCU:\SOFTWARE\Microsoft\VisualStudio\8.0\TeamFoundation\SourceControl\Checkin Policies')