Script To Check If A Process Is Running On Windows Server 2008 R2

Google drive is on Windows Server 2008 R2.  Per google, Drive on a server is not supported and I do run into issues with it stopping and thus not syncing.  

What happens is files will be saved locally on the server, but not synced up to drive.  When I rdp to the server I can see that several thousand files are not synced.  I then start up google drive and syncing starts.  

What is the best way to run a script perhaps as an automated task to make sure googledrivesync.exe is running and if not, start it up?
LVL 56
Scott Fell, EE MVEDeveloper & EE ModeratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robin CMSenior Security and Infrastructure EngineerCommented:
Here's an example that'll do it for notepad, just change it for googledrivesync and whatever the full path is to the exe:
$ProcessesCSV  = Get-Process | ConvertTo-Csv
if($ProcessesCSV -match "notepad"){
    # Already running
}
else{
    ."C:\Windows\notepad.exe"
}

Open in new window

save it as a .ps1 file and use Windows Task Scheduler to run it as often as you like. You might want to run it elevated (i.e. as an administrator), depends what the sync exe needs.
Robin CMSenior Security and Infrastructure EngineerCommented:
Actually, I like this version better (and it runs faster):
if(Get-Process -Name notepad -ErrorAction SilentlyContinue){
    # running
}
else{
    ."C:\Windows\notepad.exe"
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott Fell, EE MVEDeveloper & EE ModeratorAuthor Commented:
Awesome!  Thank you, I just implemented to run every hour and not duplicate if already running.  

Google said they are working on a server version of Google Drive as Drive is not meant to run on a server with multiple people and it does crash now and then.  This looks like a good way to make sure it is always running.
Robin CMSenior Security and Infrastructure EngineerCommented:
Scott Fell, EE MVEDeveloper & EE ModeratorAuthor Commented:
Just in case the link ever goes bad the code from above

if((Get-Process -Name notepad -ErrorAction SilentlyContinue) -eq $null){
    ."C:\Windows\notepad.exe"
}

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.