How to found if a TFS workspace is a local or server workspace
After a long search (hours and hours in the very bad msdn documentation about the tf.exe
command!), I have found the way to get the information!
First you have to use the tf.exe workfold c:\your\path
command to find out in which workspace the folder is. The command output something like that:
================================================================Workspace : NameOfYourWorkspace (John Doe)Collection: https://tfs.yourtfs.com/tfs/defaultcollection $/: C:\your\path
Then you have to extract the 'workspace' (note: we really don't know why here the tf.exe
command don't output the workspace in the format accepted everywhere by the tf.exe
command i.e. "WorkspaceName;Owner" and consequently should be adapted!) and 'collection' data to use it in the tf.exe workspaces /format:detailed
command, like that:
tf.exe" workspaces /format:detailed /collection:"https://tfs.yourtfs.com/tfs/defaultcollection" "NameOfYourWorkspace;John Doe"
The command output something like that:
===============================================Workspace : NameOfYourWorkspaceOwner : John DoeComputer : YOU_COMPUTERComment :Collection : yourtfs.com\DefaultCollectionPermissions: PrivateLocation : LocalFile Time : CurrentWorking folders: $/: C:\your\path
The important data that I want here is Location : Local
(or Server
)
I have written a little powershell script, if it could be of little use for someone to extract the data in the output to use them:
function ExtractData($text, $key){ $pattern = "^$key *: *(.+)$" $filteredText= $text | Select-String $key $found = $filteredText -match $pattern if ($found) { return $matches[1] } exit 1}$currentWorkspaceData = (& "$env:VS120COMNTOOLS..\IDE\tf.exe" workfold .)$workspace = ExtractData $currentWorkspaceData "Workspace"$found = $workspace -match "^(.+) \((.+)\)$"if (!$found) { exit 1}$workspace = $matches[1] + ";" + $matches[2]$collection = ExtractData $currentWorkspaceData "Collection"$location=(ExtractData (& "$env:VS120COMNTOOLS..\IDE\tf.exe" workspaces /format:detailed /collection:$collection $workspace) "Location")$localServer = $location -eq "Local"if($localServer){ Write-Host "Local!!!"}else{ Write-Host "Server!!!"}
This script give the answer only for the current folder but could be easily adapted...