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
2,438 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

705 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