TN WW185 How to remotely restart a Wonderware service
This article from InSource shows...
- Author: Peter Farrell
- Published: 06/29/2017
- Applies to: All products, all versions
The occasion might arise when in order to troubleshoot or recover a Wonderware service, it may need to be restarted. If the service is running on a remote machine, there is a handy way to trigger a Power Shell script ton stop, pause, and then restart a service.
Remote control of a PowerShell script which stops, pauses for a predetermined amount of time, and then starts the Wonderware Historian IO Server (InSQLIOServer) is possible, but access to the remote computer must first be turned on from within PowerShell on the machine which will be running the PowerShell script so that another machine can remotely access it to trigger and run the script.
On the remote machine on which the PS1 script will be triggered open PowerShell. With PowerShell open, enter the following command and hit enter
Enable-PSRemoting – Force
It could take up to 30 seconds or so, but you should get a command prompt back.
Using the command above, it opens all local users up to admin rights, but if you read down on the article, it tells you how to limit the remoting to only a specific computer
Set-Item wsman:\localhost\client\trustedhosts *
Replace the * with your machines IP address
Now, you should be able to create a PowerShell script on the remote machine from which you need to invoke the remote machine to run the PowerShell script.
Invoke-Command -ComputerName RemoteComputerName -FilePath c:\temp\MyPS_ScriptName.ps1
This assumes that the remote computer name is RemoteComputerName and that the path to your PowerShell script is c:\temp\ and that the script name is MyPS_ScriptName.ps1. Replace with your path and script name.
Following is an example script used to stop, pause, and then restart Wonderware’s InSQLIOServer service – note that this should work on any service. Just save from notepad as any name with a dot PS1 extension e.g. AnyName.PS1
# Get the ID and security principal of the current user account
# Get the security principal for the Administrator role
# Check to see if we are currently running "as Administrator"
# We are running "as Administrator" - so change the title and background color to indicate this
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
$Host.UI.RawUI.BackgroundColor = "DarkBlue"
# We are not running "as Administrator" - so relaunch as administrator
# Create a new process object that starts PowerShell
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
# Specify the current script path and name as a parameter
$newProcess.Arguments = $myInvocation.MyCommand.Definition;
# Indicate that the process should be elevated
$newProcess.Verb = "runas";
# Start the new process
# Exit from the current, unelevated, process
# Following three lines of code stop, pause for 10 seconds, and restart InSQLIOServer
net stop insqlioserver
net start insqlioserver