Using Developer Command Prompt for VS 2019
I am able to see a list of all my workspaces.
tf workspaces /collection:\"https://dev.azure
I recently had some issues deleting workspaces as the user who owned the workspace had left, so validation was failing to recongise their account.
This post introduced me to the XML output from the tf workspaces
command; enabling me to get the underlying id of the user and delete the workspace using that.
Here's a PowerShell wrapper that I used to delete all workspaces for the user:
Set-Alias -Name 'tf' -Value 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\TF.exe' # amend path so it points to your tf.exe file
# fetch a list of all workspaces and store them in an xml variable
$x = [xml](tf workspaces /computer:* /owner:* /format:xml)
# determine who we want to delete (this is used in our filter later; to delete all, just skip the filter
$userToDelete = 'Someone@example.com'
# for each workspace
# take those where the owner's display name matches our target user
# then delete that workspace (I've left prompts enabled, so you can manually validate things; add /noprompt to avoid that
$x.Workspaces.Workspace | ?{$_.ownerdisp -eq $userToDelete} | %{tf vc workspace /delete "$($_.name);$($_.owner)"}
More info on available options in the MS Docs; so you can tweak the above per your exact requirements.