I have a little program I wrote using the technique mentioned in a lot of places on the web to obtain the DTE2 object for a running VS instance. It is available on github - https://github.com/MarkKharitonov/RunningVSInstanceFinder. I can use it to obtain the DTE2 object from Powershell:
C:\work> git clone -q https://github.com/MarkKharitonov/RunningVSInstanceFinder
C:\work> cd .\RunningVSInstanceFinder\
C:\work\RunningVSInstanceFinder [master ≡]> dotnet build -v:q -nologo
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.06
C:\work\RunningVSInstanceFinder [master ≡]> $VSInstanceFinder = "C:\work\RunningVSInstanceFinder\RunningVSInstanceFinder\bin\Debug\net472\RunningVSInstanceFinder.dll"
C:\work\RunningVSInstanceFinder [master ≡]> add-type -Path $VSInstanceFinder > $null
C:\work\RunningVSInstanceFinder [master ≡]> $res = [Ceridian.RunningVSInstanceFinder]::Find("C:\dayforce\CSTool\CSTool.sln")
C:\work\RunningVSInstanceFinder [master ≡]> $res.DTE.Solution.FullName
C:\dayforce\CSTool\CSTool.sln
C:\work\RunningVSInstanceFinder [master ≡]>
Now I want to grab the contents of the build output pane, which is active:

But nothing I tried worked:
- Some sites suggest to inspect the
ToolWindowsproperty, but it is empty:
C:\> $res.DTE.ToolWindows
C:\>
- Some (e.g. How to get Visual Studio Output Window content via EnvDTE (Non Package)) suggest to leverage the
Windowsproperty to find the right window, but it does not work either:
C:\> $o = $res.DTE.Windows.Item([EnvDTE.Constants]::vsWindowKindOutput)
C:\> $o
System.__ComObject
C:\> $o.Object
C:\> $o.OutputWindowPanes
C:\>
I know the DTE2 object I have is good, because I can trigger a build in the VS instance:
C:\work\RunningVSInstanceFinder [master ≡]> $res.DTE.Solution.SolutionBuild.Build()
C:\work\RunningVSInstanceFinder [master ≡]>
And it indeed runs the build and the build output pane reflects that.
At this point I think to move the investigation into the C# code, but I would really like to understand what is going on in Powershell.
How can I get the Build Output pane content from VS 2022 in Powershell?