In NuGet's Package Manager Console within Visual Studio (I am using 2010 Ultimate), the following code works and successfully activates the Toolbox window:
$dte.windows.Item("{B1E99781-AB81-11D0-B683-00AA00A3EE26}").activate()
But the same code does not work in a stand-alone PowerShell console session. Here's the script I am using:
# Note: Start PowerShell console with the -STA switch.
# Get reference to VS2010 automation object (COM).
$DTE = New-Object -ComObject VisualStudio.DTE.10.0
$DTE.Solution.Open("C:\wfa1\wfa1.sln")
$DTE.MainWindow | %{$_.gettype().InvokeMember("Visible","SetProperty",$null,$_,$true)}
$DTE.Windows.Item("{B1E99781-AB81-11D0-B683-00AA00A3EE26}").Activate()
$DTE.Quit()
The error I am getting:
Method invocation failed because [System.__ComObject] doesn't contain a method named 'Item'.
At C:\users\ams\Desktop\ATS\AddTypeSample.ps1:114 char:18
+ $DTE.Windows.Item <<<< ("{B1E99781-AB81-11D0-B683-00AA00A3EE26}").Activate()
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
I know NuGet preps its console so that, for example, the $dte
variable is immediately available for use w/o having to do anything. How can I set up my PS script so that the commands will work seamlessly as they do in NuGet's console?
I am using PowerShell version 2 on Windows 7 Ultimate.