Add open-microsoft-outlook.ps1 and close-microsoft-outlook.ps1

This commit is contained in:
Markus Fleschutz 2021-11-12 12:02:07 +01:00
parent 2386fa4df9
commit 9d240326c8
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,15 @@
<#
.SYNOPSIS
Closes Microsoft Outlook
.DESCRIPTION
This script closes the Microsoft Outlook email application gracefully.
.EXAMPLE
PS> ./close-microsoft-outlook
.NOTES
Author: Markus Fleschutz · License: CC0
.LINK
https://github.com/fleschutz/PowerShell
#>
taskkill /im outlook.exe
exit 0 # success

View File

@ -0,0 +1,28 @@
<#
.SYNOPSIS
Launches Microsoft Outlook
.DESCRIPTION
This script launches the Microsoft Outlook email application.
.EXAMPLE
PS> ./open-microsoft-outlook
.NOTES
Author: Markus Fleschutz · License: CC0
.LINK
https://github.com/fleschutz/PowerShell
#>
function TryLaunching { param($Path)
if (test-path "$Path" -pathType leaf) {
start-process "$Path"
exit 0 # success
}
}
try {
TryLaunching "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE"
TryLaunching "C:\Programs\Microsoft Office\Office14\OUTLOOK.EXE"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}