Is there a way to find out if a specific folder mapped in an existing tfs workspace is a local workspace or a server workspace?
I'm mostly interested by an answer using the tf.exe
command or powershell
or even api (but not with the GUI!).
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 : NameOfYourWorkspace
Owner : John Doe
Computer : YOU_COMPUTER
Comment :
Collection : yourtfs.com\DefaultCollection
Permissions: Private
Location : Local
File Time : Current
Working 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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With