Jump to content
ethorup

Script to restart Pulseway on demand

Recommended Posts

Small Correction: The scheduled task can be run on demand, but by default it restarts the pulseway service once a day at 11am, which in theory, should force it to check for updates. 

So one of the problems I ran into with pulseway is, sometimes I would want to restart the service.  Doesn't really matter why, could be to get it to check for new updates to the pulseway agent and get them on the latest version.  The problem was that if I just setup a script to restart the service, say like this ReStart-Service "Pulseway" what would happen is that it would send the command in whatever user environment pulseway runs in, it would execute it, the service would stop, and thennnn.......... nothing! Because we stopped the service, it kills whatever user environment pulseway was using including the script and it never finishes the command.  It's really weird.  So I setup this wonderful little script that creates a scheduled task, that can be run on demand using another script.  It keeps you from running a restart service task on all your end points and suddenly losing connection with them all.... not fun.

So here is the first script you put in to pulseway.  Read the comments and change the working directory, user account and password to match what you use.  It also requires a universal user account on all your workstations that you want to use it on.

# this script will create a scheduled task that runs a powershell script that restarts the pulseway service.

# This line deletes the task if it already exists.  That way if you make changes to the task it will create a fresh copy of it.
schtasks /delete /F /tn "Restart Pulseway"

# working directory path
$workd = "c:\temp"

# Check to see if working directory exists and create if it does not.
If (!(Test-Path -Path $workd -PathType Container))

New-Item -Path $workd  -ItemType directory 
}

# Create a variable with the entire contents of the XML file used to create the scheduled task
$text = '<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2017-04-24T12:50:26.5825569</Date>
    <Author>ECHO-FAMILYPC\Echo</Author>
    <Description>this will restart the pulseway service, forcing it to check for and implement any updates.</Description>
    <URI>\Restart Pulseway</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2017-04-24T11:00:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-21-3275926025-1642913270-681481828-1006</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>true</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>Powershell.exe</Command>
      <Arguments>-ExecutionPolicy Bypass '+$workd+'\rstrtPulse.ps1</Arguments>
    </Exec>
  </Actions>
</Task>
'

# Create a variable containing the entire contents of the powershell script that will restart the pulseway service.
$text2 = 'ReStart-Service "Pulseway"'

# Pump the contents of the two variables into the actuall files to be used
$text | Set-Content $workd\rstrtPulse.xml
$text2 | Set-Content $workd\rstrtPulse.ps1

# Command that actually creates the scheduled task.  You will need to change UserName and Password to the universal admin creds that you may use.
schtasks.exe /create /xml "$workd\rstrtPulse.xml" /tn "Restart Pulseway" /ru UserName /rp Password

#Wait a couple seconds
Start-Sleep -s 2

# Delete the files when done.  Dont need anyone knowing my secrets!
del $workd\rstrtPulse.xml
del $workd\rstrtPulse.ps1

 

Here is the second script that you will use to execute the scheduled task

schtasks /run /tn 'Restart Pulseway'

 

Have fun, stay safe, always test your scripts!

Edited by ethorup
minor correction in description

Share this post


Link to post
Share on other sites

Thanks, I did use on some machines the following command to restart Pulseway from the mobile app and it did restart the service without any problems:

Restart-Service Pulseway

-Paul

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Martin Stevnhoved
      Hi.
       
      I am making an Automation Script that updates a custom plugin-file, that might is always be in use, to a newer version.
      If the plugin doesn't already exist everything works fine.
      But if it already exist it cannot be overwritten, because the Pulseway Service (and managers, if any are running) is using the file.
      My solution is to stop the service, overwrite the file and start the service.
      It works very well when executing manually in ISE, but not when executed as an Automation Script from Pulseway.
      It looks like the entire script is terminated when the service stops, and the execution doesn't return anything in execution history - not even an error.
       
      Could anyone help me with the best practice for updating a plugin dll-file from an Automation Script.
       
      Best Regards,
      Martin Stevnhoved
    • By ArrowNM
      Will be able to see in the next release an option to update time on a bulk action for multiple tickets?

    • By Keith
      I am trying to create a PowerShell script that will run DBCC checks on a SQL server and then report status back to Pulseway.  I have a working script that I can run from the command line but the script will not run correctly when sent as a Pulseway script.  Here are the details.
      The script fails because it is unable to authenticate to the SQL server.  The SQL Server is running on the same machine as I am running the script on.  Thus wil are not dealing with cross machine accounts.  I have put debug code into the script and the account reported back by PowerShell is MACHINENAME$.  The machine is in a domain and thus the script appears to be reporting back the machine account in the domain.  This implies to me that when Pulseway runs a script it is using the NT AUTHORITY\SYSTEM account and that the MACHINENAME$ account would then be used for any network access.  Is this correct?
      I have given SQL Server rights to NT AUTHORITY\SYSTEM as well as DOMAIN\MACHINENAME$ and NT AUTHORITY\LOCAL SERVICE.  Non of these rights appear to allow me to connect to SQL.  Has anyone ever written Powershell code for Pulseway and been able to connect to SQL Server?
      Any ideas, thoughts or details on the user contexts used by Pulseway would be helpful.
    • By MaxITGarrett
      Our business operates with hundreds of products in our inventory and going through all of them and manually entering them into PSA was not exactly an option, and without an import function, I had to develop an import tool that uses the PSA API. I developed it originally with hard coded parameters, in a single class, but went back today and improved it for distribution to everyone here.
      To view the source code, check out the repository at https://bitbucket.org/garrettbromley/pulseway-product-import/
      To download the executable files, download PulsewayProductImport-v2.zip at https://bitbucket.org/garrettbromley/pulseway-product-import/downloads/
       
      Instructions:
      Download the Excel template and add your inventory into that sheet. I personally had a Microsoft Surface that I walked around with and inventoried everything. To change the categories/sub categories, open the "Back End" tab on the sheet and edit those tables to your liking The only column that isn't required is the UPC Code. Run the Import Tool Input your PSA credentials Type in the full directory to the excel sheet (make sure its closed before running it) Confirm the number of detected items Watch the tool work Make a stock adjustment with the levels of stock for each item (this unfortunately cannot be automated) It will notify you how many items have successfully been imported and which ones failed (if any) and why.  
      Please let me know if you have any questions! I will post changelogs if any updates are made.
    • By pete_harris
      Does anyone have or know how to create a script to disable Password Protected Sharing in Windows 10. This has become a real issue for me as every time Microsoft has an update the default is "Turn on password protected sharing" which forces me to do a lot of tweaks.
      Thanks in advance,
      Pete
×