1

I am building a function in PowerShell that creates a new Workspace and gets the latest version of the directory specified in addition to some other TFS and file system related tasks. Right now I'm using a mixture of PowerTools and TFS assemblies to get the job done. It appears I can do just about everything with Power Tools, except creating a new workspace. I haven't figured out how to do this without explicitly loading the Team Foundation assemblies. Is it even possible and if so how?

Here's what I'm doing right now

#Install required TFS assemblies
"Microsoft.TeamFoundation.Client",
"Microsoft.TeamFoundation.VersionControl.Common",
"Microsoft.TeamFoundation.VersionControl.Client" |
    ForEach-Object { Add-Type -AssemblyName "$_, Version=11.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a" }

#Install TFS PowerTools snappin for basic tasks
If ( (Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin Microsoft.TeamFoundation.PowerShell
}

## Set applicable parameters

#Get the TFS server object
$tfs=Get-TfsServer -Name $tfsName

#Get the version control service object
#This is what I want to do with PowerTools - like a new-item or something
$vcs = $tfs.GetService([type]"Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer")

#Create a Workspace parameters object
$workspaceParameters = New-Object Microsoft.TeamFoundation.VersionControl.Client.CreateWorkspaceParameters -ArgumentList $wsName

#Create the Workspace
$tfsw = $vcs.CreateWorkspace($workspaceParameters)

# Add any working folders that you would defined below
$tfsw.Map($tfsLocation, $localFolder)
Steve Mangiameli
  • 688
  • 7
  • 15

1 Answers1

1

The only new commands in the TFPT snapin is New-TfsChangeset and New-TfsShelveset. Is there a reason you can't use tf.exe workspace /new ... and tf.exe workfold ...?

Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • No reason at all. I'm new to PoSh and managing TFS. The solutions I'm working with are just variations of what I've been able to find with my own limited knowledge. I was steered toward PowerTools but another user, but so far I'm a bit underwhelmed by what's available with regards to cmdlets. Are there any prerequisites to the tf.exe methods? Gotchas I need to be worried about? – Steve Mangiameli Apr 20 '15 at 20:26
  • Agreed on TFPT. It is an OK start but it could be doing so much more. I really miss not having a Get-TfsPermission cmdlet. We use tf.exe quite a bit in our build & test scripts. The main pre-req is to have Visual Studio (or VS Team Explorer) installed since that is what installs tf.exe. Other than that, you need to know that in order to test whether a console exe succeeds, you should check $LASTEXITCODE after invoking the exe. Also, watch out for parameters that take semi-colon. That's a statement separator PowerShell. – Keith Hill Apr 20 '15 at 20:57
  • For example, this command can cause problems with PowerShell `tf status . /r /workspace:*;johndoe`. You need to specify it like this `tf status . /r /workspace:*;johndoe`. Or if you are on V3 or higher, use the stop-parsing operator e.g. `tf status . /r --% /workspace:*;johndoe`. Note that with --%, it put's PowerShell into a CMD like parsing mode until the end of the line. – Keith Hill Apr 20 '15 at 21:00