使用 Powershell 删除以前缀开头的 Solr 核心

Use Powershell to delete Solr cores beginning with a prefix

有没有办法使用 Powershell 2.0 自动删除以给定前缀开头的 Solr 核心?例如,我想删除所有以 "some_prefix" 开头的内核。我正在使用 Solr 4.10.1,并希望通过以下 API 调用删除内核:

http://localhost:8983/solr/admin/cores?action=UNLOAD&deleteIndex=true&deleteInstanceDir=true&core=some_prefix_etc

这个脚本可以工作:

param ($prefix = $(throw "-prefix is required"))

$client = (New-Object System.Net.WebClient)
[xml]$coresXML = $client.DownloadString("http://localhost:8983/solr/admin/cores")
$cores = $coresXML.response.lst[2].lst | % {$_.name}
$success = 0
$error = 0

foreach ($core in $cores) {
  if ($core.StartsWith($prefix)) {
    $url = "http://localhost:8983/solr/admin/cores?action=UNLOAD&deleteIndex=true&deleteInstanceDir=true&core=$core"
    write-host "Deleting $core :"
    $client.DownloadString($url)
    if ($?) {$success++}
    else $error++
  }
}
write-host "Deleted $success cores.  Had $error errors."

请参阅 on how the syntax to extract cores to a list works, and this Solr UNLOAD API 删除核心的选项。