$toExecute = "tf workspaces /owner:machine\user"
Invoke-Expression -Command $toExecute -OutVariable workspacesRaw
workspaces=@()
foreach( $workspaceRaw in $workspacesRaw)
{
   if( $workspaceRaw.StartsWith("Collection") 
       -or $workspaceRaw.StartsWith("Workspace ") 
       -or $workspaceRaw.StartsWith("--------") )
   {
        continue;
   }
   $tokens = $workspaceRaw.Split(" ")
   $workspaceName = $tokens[0].Trim()
   $workspaces += $workspaceName
}

foreach( $workspaceName in $workspaces )
{
      write-host "Processing $workspaceName"
      &tf workspace /collection:http://yourtfsserver:8080/tfs/DefaultCollection /delete "$workspaceName;owner"
}
Advertisements