Store Variable Help Needed

Hello there, so I am using this awesome tool and needed some help. Have the overall script working as needed, just needed help with this part. So when the script runs, it checks to confirm if Teams and Outlook are running and if they are, prompt the user to close the apps.

What I would like to do is, if Outlook was running when the script was run, I would like to re-launch it after the script completes and if it was not running, don’t re-launch Outlook. I think I need to store this as a variable or so and I am not sure how to accomplish this small task.

Any example or help is greatly appreciated, thank you.

Since there is no -PassThru for the Show-InstallationWelcome function, you have to test for those apps BEFORE running the Show-InstallationWelcome function.

So here is the code to do that:

If (Get-Process -Name 'outlook' -ErrorAction SilentlyContinue) {
	$OutlookWasRunning = $true
} else {
	$OutlookWasRunning = $false
}

If (Get-Process -Name 'teams' -ErrorAction SilentlyContinue) {
	$TeamsWasRunning = $true
} else {
	$TeamsWasRunning = $false
}
1 Like

Thank you very much for your help on this. I had the if statement written out, but couldn’t figure out how to store the results. After looking at your example, you are using the $OutlookWasRunning as a variable to capture the result of the if statement.

You are correct, I have this code above the “Show-InstallationWelome” function. I am using this to show the user the prompt if Teams and Outlook are running.

Also, I took your variable and used it to re-launch Outlook if it was running when the script was run. Below is what I got. If outlook was not running, it doesn’t re-launch and if it was running, it will re-launch after teams with Start-Sleep -seconds ‘20’ between them.

If ($OutlookWasRunning -eq $true) {
Start-Process Outlook
}
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.