<# .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*" }