1: # Copyright © Microsoft Corporation. All Rights Reserved.
2: # This code released under the terms of the
3: # Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
4: #
5: #<#
6: #.SYNOPSIS
7: # This script configures the enviroment for the hands on labs scenarios.
8: # It is only intended to be run after the TFS enviroment is fully configured.
9: #
10: #.DESCRIPTION
11: # This script performs the following steps:
12: # 1) Creates the sample users
13: # 2) Adds the sample users to the correct TFS groups
14: #
15: #.NOTES
16: # File Name : 3-hol.ps1
17: # Author : VSTS Rangers
18: # Requires : PowerShell V1
19: #
20: #.LINK
21: # This script posted to:
22: # http://???.codeplex.com
23: # License:
24: # http://opensource.org/licenses/ms-pl.html
25: #
26: #.EXAMPLE
27: # .\3-hol.ps1
28: #>
29:
30: #Simply writes a blank to the screen
31: function blankLine
32: {
33: Write-Host -Object:""
34: }
35:
36: #Get the machine hostname
37: $hostname = hostname
38:
39: $projectName = ""
40:
41:
42: function introduction
43: {
44: blankLine
45: blankLine
46: Write-Host -ForegroundColor Yellow -Object "Welcome to the TFS 2010 Virtual Machine Configuration Script - Hands On Labs Setup"
47: "
48:
49: Copyright © Microsoft Corporation. All Rights Reserved.
50: This code released under the terms of the
51: Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
52:
53: "
54: Write-Host -ForegroundColor Red -Object "Note: Please make sure you have checked the README.TXT file for information about pre-requisites and known issues prior to running this script."
55: "
56:
57: This script is intended to configure the TFS virtual machine.
58:
59: WARNING: THIS IS NOT INTENDED FOR PRODUCTION USE!
60:
61: This script will
62: - Create sample TFS user accounts
63: - Assign TFS users to TFS groups
64:
65: If you wish to abort press Ctrl+C now, else
66:
67: Press any key to begin..."
68: $inputKey = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp")
69: }
70:
71: function createUser([string]$accountName, [string]$password, [string]$name)
72: {
73: $computer = [adsi] "WinNT://$hostname"
74: $user = $computer.Create("User", $accountName)
75: $user.SetPassword($password)
76: $user.SetInfo()
77: $user.FullName = $name
78: $user.put("UserFlags",65536 -bor 64)
79: $user.SetInfo()
80: }
81:
82: function createSampleAccounts
83: {
84: createUser "michaf" "P@ssw0rd" "Michael Affronti (PM)"
85: createUser "aprist" "P@ssw0rd" "April Stewart (Dev Lead)"
86: createUser "dorikr" "P@ssw0rd" "Doris Krieger (Dev)"
87: createUser "abuobe" "P@ssw0rd" "Abu Obeida Bakhach (Dev)"
88: createUser "chriko" "P@ssw0rd" "Christine Koch (Tester)"
89: createUser "chriba" "P@ssw0rd" "Chris Barry (Business Stakeholder)"
90: createUser "robiwo" "P@ssw0rd" "Robin Wood (End User)"
91: }
92: function addToTFS([string]$accountName, [string]$groupname, [string]$targetProjectName = "")
93: {
94: $target = ""
95: if ($targetProjectName -ne "")
96: {
97: $target = "[" +$targetProjectName + "]\" +$groupname
98: }
99: else
100: {
101: $target = $groupname
102: }
103:
104: if (!$accountName.Contains("\"))
105: {
106: $accountName = $hostname + "\" + $accountName
107: }
108:
109: $currentLocation = Get-Location
110: Set-Location "c:\Program Files\Microsoft Team Foundation Server 2010\Tools"
111: $argument = $hostname + "/defaultcollection"
112: .\tfssecurity /g+ $target n:$accountName /collection:$argument
113: Set-Location $currentLocation
114: }
115:
116:
117: function addSampleAccountsToGroups
118: {
119: addToTFS "michaf" "Team Foundation Administrators"
120: addToTFS "aprist" "Team Foundation Administrators"
121: addToTFS "dorikr" "Contributors" $projectName
122: addToTFS "abuobe" "Contributors" $projectName
123: addToTFS "chriko" "Contributors" $projectName
124: addToTFS "chriba" "Contributors" $projectName
125: addToTFS "robiwo" "Readers" $projectName
126: }
127: Clear-Host
128: introduction
129: $projectName = Read-Host -Prompt "Project name to add contributors and readers to"
130: createSampleAccounts
131: addSampleAccountsToGroups