通过 Powershell 获取 Solr Core

Get Solr Cores via Powershell

有没有办法在我的本地 Solr 实例中使用 Powershell 获取 Solr 核心列表 运行?我是 运行 Solr 4.10.1,正在使用 Powershell 2.0。

我想创建一个核心名称的文本文件:

somecore1
somecore2
etc.

我可以通过点击 URL 获得 XML 格式的核心列表:http://localhost:8983/solr/admin/cores return [=21= 的相关细节] 是:

<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>

首先,您需要将 XML 响应加载到 XML 变量:

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

现在您可以使用以下语法输出核心列表:

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

此语法声明,"In XML document, get child of root element "response",然后取第三个子节点 "lst",然后遍历其子节点并输出 "name" 属性。

要另存为文件,重定向:

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

备注: