通过PowerShell获取Solr内核 [英] Get Solr Cores via Powershell
本文介绍了通过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中解析XML的详细信息,请参阅https://blogs.technet.microsoft.com/heyscriptingguy/2012/03/26/use-powershell-to-parse-an-xml-file-and-sort-the-data/
- 我不得不使用WebClient,因为我的PowerShell版本。在3.0版中,有一个Invoke-RestMethod命令。请参见https://superuser.com/questions/344927/powershell-equivalent-of-curl
这篇关于通过PowerShell获取Solr内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文