News:

Tip: Get a notification of new posts by checking the 'Notify' button in each subforum. Or subscribe to individual replies using Profie - Modify Profile - Notifications - Turn notification on when you post or reply to a topic.

Main Menu

Command file and launching powershell script

Started by dlettani, 27 Jun 2017, 20:31:58

Previous topic - Next topic

dlettani

Hi all,

I've set up about 20 filters with labels and activated command file output with variables active.
The command file launches a batch file with one single line:
powershell -NoProfile -executionpolicy bypass -file C:\Users\David\PDWpowershell\pushover4.ps1 %1 %2 %3 %4 >>testlogbatch.txt

-> sole use of this .bat file is thus to call my Powershell script (passing the variables once more) that calls some API's on the net.  Return is written in testlogbatch.txt for troubleshooting.
In fact I enabled push messaging on my mobile phone for every message that triggers a filter using a free service  ;D
The powershell is only about 100 lines of very simple code to add some more functionality and finally calls the API for creating the push message on smartphone.

This setup works fine and is blazing fast.
There's only one thing that bothers me: whenever two filters are triggered just one after another (with just 1 second delay between both) it seems that the second launch of the same batch file fails because the first command window is still open... Once there is more than 1 second between the messages all is fine.
Anybody a clue on this?
Should I close the command prompt explicitly in my batch file and add a second line that says Exit
Should I use the 'start' command and add this in my first line of the batch file? From what I read I guess this will make sure to start every time an new session once this batc file is called?
START powershell -NoProfile -executionpolicy bypass -file C:\Users\David\PDWpowershell\pushover4.ps1 %1 %2 %3 %4 >>testlogbatch.txt

Thanks!


VidarParry

Hi David,
Looks like you've developed a good system there - I tried developing a similar solution to push the emails to SMS but wasn't successful and gave up! Would you be willing to share?

Re your problem, I think trial and error of your suggestions is the way to go - I can't help specifically on that. I assume you've Googled? You might get some help from stackoverflow - there's still a few DOS experts there!

Cheers
...Steve

dlettani

Too much to do, too little time....  >:(
I'll give it a try.

Have a look at https://pushover.net/
Download the app, create an account and head over to their website where you set up everything you need.
I started by using the email2push gateway but then wrote the script to directly call their api's and created an application key (eg; a separate channel in Puhover notifications).
Have a go and let me know if you have questions.

I'm now looking into the subscription API, just added a direct navigation Waze link based on the message text that contains the address info...

VidarParry

Know what you mean about no time!  ;D

Thanks for the info - I'll take a look at Pushover - certainly looks promising.

Cheers
...Steve

dlettani

The powershell script part that initiates the call for push message:


$uri = "https://api.pushover.net/1/messages.json"
$parameters = @{
  token = "xyz" #your app token, cf pushover.net, name it, upload icon etc this will create separate channel in the app
  user = $user #the userkey/groupkey to whom you want to address the push message
  title = $title #the title
  message = $args[0] #the 'body', here an argument of some other params in my script
 
  }


Enjoy ;-)

$parameters | Invoke-RestMethod -Uri $uri -Method Post

VidarParry


Tazz

Hi dlettani,

I've been using a Python script for a fair while to do similar granular filtration and sending to different groups with Pushover. (PDW doesn't natively support the command file going to .py files, so I have a batch which PDW addresses that then forwards the variables to the Python script.. It's dirty but it works)

I am having an issue however where when I start PDW, the command file is enabled etc - but it just doesn't call the batch file. I have to actually go in to the Filter settings, disable and re-enable the command file option.
Have you had any similar issues?

dlettani

Hi Tazz,
No, haven't encountered that one yet.. I'm using autologon and autorun utilities to make sure that whenever there was a windows update my computer and PDW starts up again and that worked several times wihtout the issue you mention.
I'm on PDW 3.12


dlettani

Strange... had to reboot my computer and now experienced the issue you described.. weird.. found any answers in the meanwhile... might be the startup filter file?

Tazz

#9
I actually stumbled upon a possible fix in the early hours of this morning whilst tinkering around...

Turns out you can run cmd.exe with a flag of /c <command or file>
Typically used for some automation type processes, however can also be used in this example!

SO... In my Filter options, for "command file" - instead of calling the batch file directly, I'm now calling C:\Windows\System32\cmd.exe
Then, in the "command file arguments" section I have /c C:\Users\Tazz\batch.bat %1 "%8" "%7"

IN FACT, I have just discovered I can take a link out of the chain and call my Python script directly as .py's are registered as executables..
SO, my "command file arguments" section now has /c C:\Users\Tazz\pushover.py %1 "%8" "%7"


In your scenario, I imagine your command file could call C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
And your arguments could possibly then be -NoProfile -executionpolicy bypass -file C:\Users\David\PDWpowershell\pushover4.ps1 %1 %2 %3 %4

Or similar... Let me know how you go!

dlettani

Ha, genius, thanks!
I'll give it a go, hopefully this will indeed sort the issue we've experienced before.

I love this Pushover implementation!  ;D

dlettani

Has been implemented. I noticed there is a scheduled update this evening on my pc with reboot so results coming up bit later...

Sub16

Hi guys i look for a PDW tool that allows you to send your filter pager message to pushover can any one help me thank you.

dlettani

You'll have to use the output command and then write a (powershell) script to relay that info to Pushover. That's how I did it and that worked flawless...

Sub16

hey dlettani where did you get the symbols form ? for the pushover ??