title: vs2013 create mapping to new source location using powershell
body: <p>I have been trying to automate the local setup Visual Studio (2013) workspace. I have been able to make the connection to the source location using PowerShell, but I cannot get the local mapping to apply. If I manually map the source location, I can get the local mapping to apply with PowerShell.  I have borrowed heavily from other Stack Overflow threads, but I cannot seam to find a way to map the TFS server and map the local paths to the workspace.  Thanks!</p>
  
  <pre><code>clear host
  
  [string]$TfsUrl = 'https://xxxx.visualstudio.com'
  
  '.Client', '.VersionControl.Client', '.VersionControl.Common', '.WorkItemTracking.Client', '.Build.Client', '.Build.Common' |
  ForEach-Object {
      Add-Type -AssemblyName "Microsoft.TeamFoundation$_, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
  }
  
  try
  {
      $uri = New-Object System.Uri -ArgumentList $TfsUrl
      $credentialProvider = new-object Microsoft.TeamFoundation.Client.UICredentialsProvider
      $collection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($uri, $credentialProvider)    
      $collection.Authenticate()
  
      if ($collection.HasAuthenticated)
      {
          Write-Host -ForegroundColor Green 'Connection to TFS Successful'
          $tfs = '' | Select-Object Collection, VersionControlServer, WorkItemStore, BuildServer, IdentityManagementService        
          $tfs.Collection = $collection
  
          $tfs
      }
  }
  catch
  {
      Write-Host -ForegroundColor Red $_.Exception.Message
      Write-Host
      Write-Host -ForegroundColor Red 'Failed to connect to TFS'
  }
  
  $tfsServer = "https://xxxx.visualstudio.com"
  $computerName = [system.environment]::machinename
  $folderName = "C:\VSTS_WB\xxxx.DuckCreek"; 
  
  $dir = 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\'
  Set-Alias tf "$dir\tf.exe"
  
  new-item -itemtype directory -path $folderName -force
  
  cd $folderName
  
  tf workfold "$/xxxx.DuckCreek" $folderName /map
  
  tf workfold "$/xxxx.DuckCreek/BR1/Policy/Source" "C:\Program Files\Duck Creek Technologies" /map
  
  tf workfold "$/xxxx.DuckCreek/BR1/Policy/Source/Shared.x86" "C:\Program Files (x86)\Duck Creek Technologies" /map
  
  tf workfold "$/xxxx.DuckCreek/BR1/Billing/Source" "C:\Program Files\Duck Creek Technologies Billing" /map
  </code></pre>