Get work item store from Tfs using powershell
How to get WorkItemStore from TFS using powershell?
I've tried the following:
function get-tfs {
param(
[string] $ServerName = "http://MyServer:8080/tfs"
)
begin{}
process
{
[psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
return $tfs
}
end{}
}
[Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.WorkItemTracking.Client.dll")
The above code runs fine and I have a value for $ tfs.
Then I do this:
$wis = $tfs.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
But $ wis is null. The same if I do this instead:
$wis = $tfs.TfsTeamProjectCollection.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
Also, if I do that, PowerShell says it can't find the assembly "Microsoft.TeamFoundation.WorkItemTracking.Client", even though it just found it and loaded it a second time: Add-Type -AssemblyName Microsoft.TeamFoundation.WorkItemTracking.Client
I don't understand why he found the assembly and then suddenly couldn't find it.
What am I doing wrong?
+3
source to share
2 answers
Something like this works for me:
function get-tfs
{
param([string] $ServerName = "http://myserver:8080/tfs")
$binpath = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0"
Add-Type -path "$binpath\Microsoft.TeamFoundation.Client.dll"
Add-Type -Path "$binpath\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
$creds = New-Object Microsoft.TeamFoundation.Client.UICredentialsProvider
$teamProjectCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection $ServerName,$creds
$ws = $teamProjectCollection.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
return $ws
}
+4
source to share