My job is to create a script which determines if Outlook is open, if it is open. The script should open a prompt and ask:
Outlook is open, press Yes to close outlook and continue with the script or press no to exit the script.
I can give you the code I already have, my problem is the code works apart from determining if it is really running, this means it opens the prompt always even when Outlook is closed.
$ProcessActive = Get-Process outlook.exe -ErrorAction SilentlyContinue
if($ProcessActive -eq $null)
{
#prompt yes or no
$a = new-object -comobject wscript.shell
$intAnswer = $a.popup("Outlook seems to be open; Press Yes if you want to close Outlook and continue or press No to terminate the script", `
0,"Delete Files",4)
If ($intAnswer -eq 6) {
#kill outlook
$ProcessName = "outlook"
If ($Process = (Get-Process -Name $ProcessName -ErrorAction SilentlyContinue)) {
"Closing $($ProcessName) ..." | Write-Host
$Process.Kill()
}
}
#exit script
else {
exit
}