1: param (
2: [string]$tfsServer = "TFSServerName",
3: [string]$tfsLocation = "$/TFS/Project",
4: [string]$localFolder ="c:\scripts",
5: [string]$file,
6: [string]$checkInComments = "Checked in from PowerShell"
7: )
8: $clientDll = "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\Microsoft.TeamFoundation.Client.dll"
9: $versionControlClientDll = "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\Microsoft.TeamFoundation.VersionControl.Client.dll"
10: $versionControlCommonDll = "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\Microsoft.TeamFoundation.VersionControl.Common.dll"
11:
12: #Load the Assemblies
13: [Reflection.Assembly]::LoadFrom($clientDll)
14: [Reflection.Assembly]::LoadFrom($versionControlClientDll)
15: [Reflection.Assembly]::LoadFrom($versionControlCommonDll)
16:
17: #Set up connection to TFS Server and get version control
18: $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsServer)
19: $versionControlType = [Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer]
20: $versionControlServer = $tfs.GetService($versionControlType)
21:
22: #Create a "workspace" and map a local folder to a TFS location
23: $workspace = $versionControlServer.CreateWorkspace("PowerShell Workspace",$versionControlServer.AuthenticatedUser)
24: $workingfolder = New-Object Microsoft.TeamFoundation.VersionControl.Client.WorkingFolder($tfsLocation,$localFolder)
25: $workspace.CreateMapping($workingFolder)
26: $filePath = $localFolder + "\" + $file
27:
28: #Submit file as a Pending Change and submit the change
29: $workspace.PendAdd($filePath)
30: $pendingChanges = $workspace.GetPendingChanges()
31: $workspace.CheckIn($pendingChanges,$checkInComments)
32:
33: #Delete the temp workspace
34: $workspace.Delete()