Powershell script to List all "Shared Files" in Visual Source Safe (VSS)
My current engagement is to help a client migrate from VSS to TFS. One of the features in VSS that doesn't exist in TFS is "Shared" or "Linked" files. In VSS if you "Share" a file - it really only exists in one place - and creates "Links" across the folders. So if you check it out in one place and check it back in - it will appear to the user that the change was checked in to all those other locations as well.
While the VSSMigration tool gives a report of all of these (and in fact just makes duplicate copies with no link) - the report is very detailed - and it would require some "Parsing" - so instead I wrote a Powershell script to find them. This script uses COM interop to access VSS.
Here's the script. One thing to note is a quirk of COM Interop the line Write-Output "$($item.Spec)" to get the actual value of the "Spec" property.
The parameter is the VSS "Path" you want to search from (in "$/Folder" format). If you leave it blank, it will search from the Root ($) Also note the Trap command - it was necessary as the exception from the "$VSSDatabase.VSSItem("$VSSPath")" call is a non-breaking error.
param ($VSSPath="")
function Check-Item($item) {
if ($item.Type -eq 0) {
#item is a folder
foreach ($child in $item.Items())
{Check-Item($child)}
}
else {
#item is a file
if ($item.Links.Count -gt 1)
{
Write-Output "$($item.Spec)"
}
}
}
$VSSDatabase = new-object -com SourceSafe
$VSSDatabase.Open()
#break on any error
trap
{
break
}
$VSSProject = $VSSDatabase.VSSItem("$VSSPath")
$VSSHash = @{}
Check-Item $VSSProject