View Single Post
Old 11-03-2017, 04:00 PM   #7
CRussel
(he/him/his)
CRussel ought to be getting tired of karma fortunes by now.CRussel ought to be getting tired of karma fortunes by now.CRussel ought to be getting tired of karma fortunes by now.CRussel ought to be getting tired of karma fortunes by now.CRussel ought to be getting tired of karma fortunes by now.CRussel ought to be getting tired of karma fortunes by now.CRussel ought to be getting tired of karma fortunes by now.CRussel ought to be getting tired of karma fortunes by now.CRussel ought to be getting tired of karma fortunes by now.CRussel ought to be getting tired of karma fortunes by now.CRussel ought to be getting tired of karma fortunes by now.
 
CRussel's Avatar
 
Posts: 12,287
Karma: 80074820
Join Date: Jul 2010
Location: Sunshine Coast, BC
Device: Oasis (Gen3),Paperwhite (Gen10), Voyage, Paperwhite(orig), iPad Air M3
Restart-myCalibreServer.ps1

I use a simple PowerShell script on my desktop to force a restart of the Calibre-Server process running on my network share. Works well, and I can run it from any one of several desktops/laptops in the house to trigger a restart of calibre-server.
Spoiler:

Code:
<#
.Synopsis
Restarts the calibre server process on a remote computer
.Description
Restart-myCalibreServer opens a PSSession to the remote computer (wss-200 by default) and then
stops and restarts the calibre-server process on that remote computer.
.Example
Restart-myCalibreServer

Opens a PSSession to wss-200 and stops any existing calibre-server process, and then starts a new one.
.Example
Restart-myCalibreServer -ComputerName SRV2

Opens a PSSession to SRV2 and stops any existing calibre-server process, and then starts a new one.
.Parameter ComputerName
The computer where the calibre-server is running.
.Inputs
[string]
.Notes
    Author: Charlie Russel
 Copyright: 2017 by Charlie Russel
          : Permission to use is granted but attribution is appreciated
   Initial: 10 July, 2017 (cpr)
   ModHist:
          :
#>
[CmdletBinding()]
Param(
     [Parameter(Mandatory=$False,Position=0)]
     [alias("Name","Computer")]
     [string]
     $ComputerName = "wss-200"
     )

If (! (Get-PSSession -ComputerName $ComputerName | Where-Object {$_.State -eq 'Opened'} )) {
   Write-Verbose "No existing open PSSession to wss-200 found, starting a new one"
   New-PSSession -ComputerName $ComputerName
} else {
   Write-Verbose "Found existing PSSession, reusing it..."
}
$session = Get-PSSession -ComputerName $ComputerName | Where-Object {$_.State -eq 'Opened'}
Invoke-Command -Session $session  `
               -ScriptBlock {
                  if (Get-Process -Name "Calibre*") {
                        Stop-Process -Name "calibre*"
                     }
                  Start-Process -WindowStyle Hidden `
                                -FilePath 'C:\Program Files\Calibre2\Calibre-Server.exe' `
                                -ArgumentList "D:\ServerFolders\Kindle"
                  Get-Process -Name "calibre*"
               }
CRussel is offline   Reply With Quote