Discovery Pattern Step - Need help formatting a powershell script for use in pattern designer

andy m_1
Giga Contributor

My company is in the process of migrating probes to patterns, and I'm currently working on the SQL Server Instance class pattern "MSSql DB On Windows". 

Our probe discovery had a customized powershell script that retrieved SQL Server Always On/Availability Group information.  I'm trying to run this custom script in a pattern step using the KB article How to run powershell script in patterns, but not having luck.  I've tried using the "Set Parameter Value" step with an EVAL() statement in the value, as well as the "Parse Command Output" step.  Neither is producing results for me.  Error info provided below.

The powershell script i need to run is a lot more complex than the examples provided by the KB article, but I have to believe there's a way to accomplish what I need.

 

Can someone please help?

 

I've attached the PS script that I'd like to run.  Here's the error info that I get when I try to test using the "Parse Command Output" command

Groovy code failure: startup failed: Pattern: null, Step: Untitled Step, Hash: 52905630: 8: unexpected token: $myInstanceName @ line 8, column 50. ryAvailabilityGroup ([string] $myInstanc ^ 1 error

 

 

 

1 ACCEPTED SOLUTION

andy m_1
Giga Contributor

as @ggarcia suggested, I was able to accomplish my goals by uploading my ps script to the "uploaded files" table under pattern designer, using a "put file" step to select the powershell file, then parse command output to execute the file.   The oob pattern example was very helpful - Windows OS - Servers pattern : Windows -Cloud : Windows - AWS or Windows - Azure.

 

 

 

find_real_file.png

 

 

find_real_file.png

 

View solution in original post

7 REPLIES 7

ggarcia1
Mega Guru

The issue via patterns is that powershell is run from cmd; so a lot of escaping/joining/line terminating needs to be put in place to prevent the cmd shell from incorrectly interpreting things like a pipe, breaks or even quotes.

This helped me a lot:

https://stackoverflow.com/questions/45224759/using-multi-line-powershell-commands-from-cmd-exe

 

Also, patterns can drop a file and then trigger it; that might be a better option for you considering the complexity of your script. The files I've seen so far OOB are much simpler, but they don't have any of the funky escaping; just looks like normal powershell.

Take a look at the Windows OS - Servers pattern : Windows - Cloud : Windows - AWS or Windows - Azure to see and example of putting a file then running it. I think the script would need to be loaded to 'Uploaded Files' under the Pattern Designer application.

Thank you for the response!  I ended up using the put file method you described.

andy m_1
Giga Contributor

as @ggarcia suggested, I was able to accomplish my goals by uploading my ps script to the "uploaded files" table under pattern designer, using a "put file" step to select the powershell file, then parse command output to execute the file.   The oob pattern example was very helpful - Windows OS - Servers pattern : Windows -Cloud : Windows - AWS or Windows - Azure.

 

 

 

find_real_file.png

 

 

find_real_file.png

 

hi @andy m_1 

 

I have a similar requirement, I am trying to add .ps1 file to Uploaded files but .ps1 file is not allowed as attachment. How did you upload it?