Script to Connect to Visual Studio DTE

I had seem some code about it, but now that I am constantly using Visual Studio C# interactive console, I thought:
"I should be nice to be able to just connect to the DTE in order to extract some project information"
And it seems that it is not that difficult. So first evaluate the following snippet.

#r "C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\PublicAssemblies\envdte.dll"
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using EnvDTE;
using System.Linq;

public IEnumerable<DTE> GetInstances()
    IRunningObjectTable rot;
    IEnumMoniker enumMoniker;
    int retVal = GetRunningObjectTable(0, out rot);

    if (retVal == 0)
        rot.EnumRunning(out enumMoniker);

        IntPtr fetched = IntPtr.Zero;
        IMoniker[] moniker = new IMoniker[1];
        while (enumMoniker.Next(1, moniker, fetched) == 0)
            IBindCtx bindCtx;
            CreateBindCtx(0, out bindCtx);
            string displayName;
            moniker[0].GetDisplayName(bindCtx, null, out displayName);
            //Console.WriteLine("Display Name: {0}", displayName);
            bool isVisualStudio = displayName.StartsWith("!VisualStudio");
            if (isVisualStudio)
               Console.WriteLine("Display Name: {0}", displayName);
                object obj;
                rot.GetObject(moniker[0], out obj);
                var dte = obj as DTE;
                yield return dte;

private static extern void CreateBindCtx(int reserved, out IBindCtx ppbc);

private static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot);

Afer that you can evaluate:
var dtes = GetInstances().ToArray();

That is because if you have several VS instances you will have several dtes.
After that you can start using the DTE.
For example: