Get Solr Cores via Powershell

2019-07-26 23:07发布

Is there a way to use Powershell to get a list of Solr cores running in my local instance of Solr? I am running Solr 4.10.1, and am using Powershell 2.0.

I would like to create a text file of core names:

somecore1
somecore2
etc.

I was able to get a list of my cores in XML format by hitting this URL: http://localhost:8983/solr/admin/cores The pertinent details of the return XML are:

<response>
  <lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">2663</int>
  </lst>
  <str name="defaultCoreName">collection1</str>
  <lst name="initFailures"/>
  <lst name="status">
    <lst name="somecore1">
       <!-- Details removed -->
    </lst>
    <lst name="somecore2">
      <!-- Details removed -->
    </lst>
  </lst>
</response>

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-26 23:19

First, you need to load the XML response to an XML variable:

[xml]$cores = (New-Object System.Net.WebClient).DownloadString("http://localhost:8983/solr/admin/cores")

Now you can output the list of cores with this syntax:

$cores.response.lst[2].lst | % {$_.name}

This syntax states, "In XML document, get child of root element "response", then take the third child "lst", then iterate through its children and output the "name" attribute.

To save as a file, redirect:

$cores.response.lst[2].lst | % {$_.name} > c:\temp\cores.txt

Notes:

查看更多
登录 后发表回答