?
Solved

Powershell command to check to see if microsoft outlook is open and close it if it is.  If it isn't open continue without showing an error.

Posted on 2014-07-25
6
Medium Priority
?
2,642 Views
Last Modified: 2014-08-05
Powershell command to check to see if microsoft outlook is open and close it if it is.  If it isn't open continue on to other commands without showing an error.
0
Comment
Question by:FOX
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 40220353
Try this:
$ProcessName = "outlook"
If ($Process = (Get-Process -Name $ProcessName -ErrorAction SilentlyContinue)) {
	"Closing $($ProcessName) ..." | Write-Host
	$Process.Kill()
}
"Continuing with other commands ..." | Write-Host

Open in new window

0
 
LVL 22

Expert Comment

by:Christopher McKay
ID: 40220361
In Powershell, you can use this command:

kill -processname Outlook*

If Outlook is running, it will kill it, if not, it will not throw an error.

Hope this helps!

:o)

Bartender_1
0
 
LVL 16

Author Comment

by:FOX
ID: 40220402
@obda- That was unresponsive
@Bartender_1- That command works but if a user has an unfinished email it doesn't prompt for saving before closing out.

All I have this line    Get-Process OUTLOOK | % { $_.CloseMainWindow() }   which closes outlook out if outlook is open however  It even prompts the user to save if an email is in the process of being made which is good.  However it throws an error if outlook is closed as the process is not running.  I need something to check to see if outlook is running if not continue on, if it is open, close gracefully with the above command.
0
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
LVL 22

Expert Comment

by:Christopher McKay
ID: 40220427
Try this:

Get-Process OUTLOOK  -ErrorAction SilentlyContinue| % { $_.CloseMainWindow() }

Hope this helps!

:o)

Bartender_1
0
 
LVL 16

Accepted Solution

by:
FOX earned 0 total points
ID: 40232380
All- Thanks for the input but I ended up using my original command of
Get-Process OUTLOOK | % { $_.CloseMainWindow() }  If no new emails were started it closed outlook.  If new emails were in the process of being written it would prompt to ask if you want to save the email, but if the email was minimized the user would not see this.  I incorporated a message popup that read
msg * Please close Microsoft Outlook if not already closed in order for the install to complete successfully then press OK

the 2 commands ended up being:
Get-Process OUTLOOK | % { $_.CloseMainWindow() }
msg * Please close Microsoft Outlook if not already closed in order for the install to complete successfully then press OK
msg.JPG
0
 
LVL 16

Author Closing Comment

by:FOX
ID: 40240785
I needed something that would close outlook gracefully if no new emails were opened and minimized.  If emails were opened and minimized and I used a force to close all outlook sessions sensitive or C-level users could have lost emails they were creating.  Using the combined commands in this solution shuts down outlook gracefully.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question