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 dpbklyn
      Hello and Thank you in advance.
      What is the best way to setup monitoring on an agent and then push that agent out to all desktops?  Would doing an EXPORT/IMPORT on Group Policies accomplish this? 
      Thank you,
      dp
    • By kasey.tomasek
      I've noticed lately that when I have a remote session live on a machine, my local keyboard input is not being accepted in items such as Notepad, Chrome, Outlook, etc. This seems fairly system wide and I'm not always able to replicate the problem. This is likely something to do with the keyboard forwarding method, but I can't isolate this myself. Also, this does occur on several different machines - not one workstation in particular. As soon as I close the remote session, the keyboard functions normally in my local Windows 10 environments.
      Good luck with this one - it seems very transient.
    • By Quenten Grasso
      Hey Guys,
      It would be great if we had some integration with https://chocolatey.org for windows package management, its basically like apt-get or yum for windows which seems a lot better IMHO then ninite type solutions. 
      Having its own tab under group policy for example to install selected apps across multiple machines and keep them updated within patch windows for example. This would be a huge benefit for Pulseway if done well.
      https://chocolatey.org/about
      https://chocolatey.org/pricing at only $3/year per machine its pretty competitive pricing.
      Cheers,
      Quenten
    • By Quenten Grasso
      Hey Fellow PW users,
      I've created a script which allows the system to change its name to %computername%-Current logged on username, which makes life a little easier when trying to remote to their computers on the remote control tool/Webapp.
      To get started, create your script in the script editor, in my example,
      Name: Update Computer Name with Logged on Username
      Windows/Powershell Code: 
      $pwqusers = quser | Select-Object -skip 1 $pwquserfmt = $pwqusers.substring(1,22).Trim() -join "," Set-ItemProperty -Path "HKLM:\Software\MMSOFT Design\PC Monitor\" -Name ComputerName -Value "$env:computername-$pwquserfmt" Click Save.
      Next we create at new task,
      Name: Update Computer Name with Logged on Username
      Current Scope -> Windows Workstations
      Enable Scheduling -> (I've set it to run once a day) Every weekday (Monday to Friday), starting on 12 August 2018 at 09:00 (Australia/Brisbane)
      Scripts tab, Select/add your new script you just created and once that's done click save.
      You can now run the task on demand as well which will update all of the PC's in your windows workstations scope to Computer Name-Logged on usernames
      This works for RDSH hosts as well however it could get a bit of out hand if you have 5-10+ users logged in so I probably wouldn't recommend it to be used on servers.
      I Hope this helps you somehow, these scripts/suggestions come with no warranty and I bear no responsibility if this breaks anything, use at your own risk etc..etc..
      Cheers,
      Quenten
    • By Dennis Cox
      My predecessor had created a script that would install a desktop link to our help desk. We no longer use this solution and I want to have the shortcut removed from every device. I can't seem to find a script to do this. I hope someone could help.

      This is the script that he had used:
      @echo off
      md C:\icon
      copy "\\edmws001\image\Nortrux_Helpdesk_icon.ico" "c:\icon"
      icacls "C:\Users\Public\Desktop\Nortrux IT Help Desk.lnk" /inheritance:r /grant Administrators:F
      icacls "C:\Users\Public\Desktop\Nortrux IT Help Desk.lnk" /inheritance:r /grant Users:F
      icacls "C:\Users\Public\Desktop\Nortrux IT Help Desk.lnk" /inheritance:r /grant INTERACTIVE:F
      attrib -R  "C:\Users\Public\Desktop\Nortrux IT Help Desk.lnk"
      copy "\\edmws001\image\Nortrux IT Help Desk.lnk" "C:\Users\Public\Desktop"
      attrib +R  "C:\Users\Public\Desktop\Nortrux IT Help Desk.lnk"
      icacls "C:\Users\Public\Desktop\Nortrux IT Help Desk.lnk" /inheritance:r /grant Users:R
      icacls "C:\Users\Public\Desktop\Nortrux IT Help Desk.lnk" /inheritance:r /grant Administrators:R
      icacls "C:\Users\Public\Desktop\Nortrux IT Help Desk.lnk" /inheritance:r /grant INTERACTIVE:R
      icacls "C:\Users\Public\Desktop\Nortrux IT Help Desk.lnk" /inheritance:r /grant SYSTEM:F
×