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,023 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
  • 3
  • 2
6 Comments
 
LVL 83

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now