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,326 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 84

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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

SuperAntiSpyware Licenses Discounted by 25% !

Exclusive offer to Experts Exchange Members!
Buy SuperAntiSpyware License(s) from us and save 25% on the regular purchase price.
- Includes Full SuperAntiSpyware Vendor Support Entitlements
- Your Subscription does not begin until you activate your license
- Buy for your friends

Question has a verified solution.

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

By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

738 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