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
1,763 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 82

Expert Comment

by:oBdA
Comment Utility
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:Bartender_1
Comment Utility
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
Comment Utility
@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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 22

Expert Comment

by:Bartender_1
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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.
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…

763 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

13 Experts available now in Live!

Get 1:1 Help Now