troubleshooting Question

Access a currently running PowerShell script from another program

Avatar of Aludaan
AludaanFlag for United States of America asked on
Powershell
4 Comments2 Solutions67 ViewsLast Modified:
I am not sure how to make this clear so hopefully I ask this correctly. I have programmed in a few different languages but I am new to PowerShell. I am trying to find out if there is a way to have a PowerShell script running in the background waiting for some variables from another application which it will process. Nothing needs to be returned to the application calling the PowerShell script.

So what I am doing right now is I have a program that when a certain event occurs it will trigger a script. The program will pass the same 5 fields to the script every time. The script then runs a SQL query and loads every row from a database which contains a list of possible matches for the event that occurred based off all 5 fields. It then processes each row eliminating the rows that don't match the criteria.

So for example say an event occurs, it will trigger a script as follows:
script1.ps1 data1 data2 data3 data4 data5

The important part of why I am asking is script1 starts by accessing our database and loading 1,000 rows of data with 5 fields for each row. This is important because this is the same data almost every time and it seems like it would be more efficient if I could just keep it in memory.

The script then begins to step through each row discarding each row that does not match.

So if data1=field1 then keep it else discard it. At the end of this we may have 100 rows left and then it will process the next set of data the same way. If data2=field2 then keep it else discard it. And I do the same for all 5 fields further narrowing down the results each time. At the end there is stuff I do based off the remaining results which aren't important.

Occasionally the 1,000 rows of data on the SQL server which we load at the start of the script will be changed (and to be clear it is not always exactly 1,000 rows, I was using that for my example) so it is not the same EVERY time but it changes rarely. Perhaps once per day or less.

So rather than load the 1,000 rows at the start of the script every time and then discarding it again just to reload the same data I was thinking I could just have the program run in the background with the 1,000 rows pre-loaded and access it directly. If that is the case then instead of using a database I would switch it to a CSV file which would be more convenient for us and just use a hash to identify if the file has changed and if not continue to use the rows already in memory. If it has changed then dump the existing array and reload the data accordingly.

I can't show you code as I have not programmed this yet because I wanted to find out if it was possible before coding it but please feel free to ask any questions you need to try and help clarify my endless ramblings above.
SOLUTION
Dustin Saunders
Co-Founder and Chief Architect
Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros