views:

39

answers:

2

My mission is to graduate from using PowerShell to create an instance of Outlook to simply viewing, or making visible the process that I can see in the TaskManager.

To Digress, this works for Word, but not if I substitute Outlook. for Word.

$MsApp = New-Object -comObject Word.Application

$MsApp.Visible = $true

I have checked the methods but cannot find a suitable verb to open, run or make visible. I would be so grateful for a solution.

A: 

If you want to make visible an already running instance of Word or Outlook, you don't want to use New-Object. You want to get the running object. You can do this with a .NET call:

$word = [Runtime.InteropServices.Marshal]::GetActiveObject("Word.Application")
$word.Visible = $true
Keith Hill
Thanks Keith, I'll try it tomorrow.
Guy Thomas
It works for WORD, but not for Outlook.
Guy Thomas
+3  A: 

To activate a running Outlook that's just minimized:

[Runtime.InteropServices.Marshal]::GetActiveObject("Outlook.Application").ActiveWindow().Activate()

To create an Outlook instance that's visible (it's simplest to just start outlook.exe):

(new-object -com Outlook.Application).GetNamespace("MAPI").GetDefaultFolder("olFolderInbox").GetExplorer().Display()

To make the code clearer:

$outlook = new-object -com Outlook.Application
$namespace = $outlook.GetNamespace("MAPI")
$folder = $namespace.GetDefaultFolder("olFolderInbox")
$explorer = $folder.GetExplorer()
$explorer.Display()
Jaykul
Brilliant - Just what I wanted, thank you.
Guy Thomas