I have a Win 2012 R2 Server that runs unattended with apps dependent on MS Outlook 2013 running. I would like to create a daily scheduled PowerShell script to gently close Outlook, create a backup of VbaProject.OTM, and restart outlook.

The following seems to work, but I am unsure if the shutdown of Outlook is ok, and would appreciate comments if there is a better way.

stop-process -name OUTLOOK -EA SilentlyContinue

$date = get-date -format "MMddyyyy HHmm"
$fnft = "VbaProject - " + $date + ".OTM"
$source = "C:\Users\OCCReportManager\AppData\Roaming\Microsoft\Outlook\VbaProject.OTM"
$dest = "D:\FD Automation VBA Backups\" + $fnft
copy-item $source $dest
(Get-ChildItem $dest).LastWriteTime = Get-Date
$dest = "G:\PUBLIC\Mission Control\Flight Deck\Automation Source File Repository\" + $fnft
copy-item $source $dest
(Get-ChildItem $dest).LastWriteTime = Get-Date

start-process outlook
Get-Process Outlook | Foreach-Object { $_.CloseMainWindow() | Out-Null } | stop-process –force

This is what I would recommend. I stole it from Here a few weeks ago and have used it for a couple of similar projects and it appears to work without causing any hassle or abruptly killing processes (unless they were already hung).

Another solution I have used before is to setup a login script for a user which (in your case would) does the backup and then launches outlook. I then scheduled a reboot of the server every night which would allow windows to handle the stopping of the processes. This unfortunately comes with the caviate that you need to enable autologon so that the application can run in a users context... although setting a 1 minute passworded screensaver and locking the server in a comms/computer room will vastly reduce the likelyhood of the server being abused

Hopefully this is what you need

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.