Forum Discussion

WRKMC's avatar
WRKMC
Icon for Neophyte rankNeophyte
6 days ago

Get all instances WildValues from under particular Datasource - Powershell script

Hi,

I'm trying to find powershell equivalent of groovy code:
def listOfWildValues = datasourceinstanceProps.values().collect { it.wildvalue }

It is described here: https://www.logicmonitor.com/support/logicmodules/datasources/data-collection-methods/batchscript-data-collection

What I want to achieve is to get all instances from under Datasource to iterate later in script.

  • I also would like to know if there is an equivalent option for Powershell.

    But I have a feeling there isn't. I think groovy has the option because the collector itself is written in Java and can likely share objects between them. I think with PowerShell they are just opening powershell sessions and sending commands to it via input buffer/pipe (SSE). I think that is why they use a kinda hacky method to pass tokens via find-and-replace of ##token## text instead of passing objects.

    As a work around, when I create BatchScripts I would have the same code that is in the Active Discovery section in the Collection section and just redetect the instances. Many times the code for both sections are the same and I just have a IsAD=true/false at the start with an IF statement to control what output it provides. Actually some of LM's own DataSources work this way (where I got the idea) which also leads me to believe an equivalent option is not available.

  • I was hoping that it would be possible somehow. Thanks for the answer.

    I know about the discovery part you mentioned; however, in my example, I manually added instances under DS. I planned to pick all instances at once, but I have to change my approach now.

    • Joe_Williams's avatar
      Joe_Williams
      Icon for Professor rankProfessor

      This would be hacky, but you could technically get the instances by calling the LM API from inside your datasource.