I'm trying to create a powershell script, which creates new Team Projects in a given Team Project Collection. This script will have to run on the Team Foundation Server.
I'm using Team Foundation Server 2012, Visual Studio Team Explorer 2012 and TFS Power Tools 2012.
The script (based on this):
$tpcUrl = "http://localhost:8080/tfs/mycollection";
$teamproject = "TestProject"
tfpt.exe createteamproject /collection:$tpcUrl /teamproject:$teamproject /processtemplate:"Microsoft Visual Studio Scrum 2.2" /sourcecontrol:"New" /noportal /noreports
This works if I only run it once (if I only have to add one project), but when I run it again (with a different project name, of course), it gives an exception:
System.InvalidOperationException: Unexpected error occurred
when Visual Studio tried to load Team Foundation Server client application.
at Microsoft.TeamFoundation.PowerTools.CommandLine.TeamProjectCreator.CreateProject()
I found only one solution for this exception here, but it did not help, because I'm not running TFS Admin tool while the exception occurs.
I could only make this work if I manually (in TfsMgmt.exe) restart the collection (stop and start collection, not detach and attach). After that, the script worked, but again only for one new project. However, this is not a good solution, since I cannot restart a collection from script, so the project creation would require manual actions, which defeats its purpose.
This only occurs when I run this script on the Team Foundation Server, it works if I try to run it from my development PC. The problem is that I have to run it on the server.
Has anyone met this exception? Is there a way to fix it? Or is there a way I can restart a collection from script?
Edit:
There are no error messages on Logs page in TFS Administrator Console, or in the Event Viewer.