通过PowerShell获取Solr内核 [英] Get Solr Cores via Powershell

查看:0
本文介绍了通过PowerShell获取Solr内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

somecore1
somecore2
etc.

我通过点击以下URL:http://localhost:8983/solr/admin/cores能够获得XML格式的内核列表:返回的XML的相关详细信息为:

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

此语法声明:"在XML文档中,获取根元素的子元素"Response",然后获取第三个子元素"lst",然后迭代其子元素并输出"name"属性。

要另存为文件,请重定向:

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

备注:

这篇关于通过PowerShell获取Solr内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆