Link to home
Start Free TrialLog in
Avatar of Scott Fell
Scott FellFlag for United States of America

asked on

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?
Avatar of Robin CM
Robin CM
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
ASKER CERTIFIED SOLUTION
Avatar of Robin CM
Robin CM
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scott Fell

ASKER

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.
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