powershell Splunk使用PowerShell导出搜索作业

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell Splunk使用PowerShell导出搜索作业相关的知识,希望对你有一定的参考价值。

# Conversion of http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#search.2Fjobs.2Fexport 
# example using curl, to PowerShell with Invoke-RestMethod cmdlet
#
# $ curl -k -u admin:changeme https://localhost:8089/services/search/jobs/export 
#        --data-urlencode search="search index=_internal | stats count by sourcetype" 
#        -d output_mode=json -d earliest="rt-5m" -d latest="rt"

$cred = Get-Credential

# This will allow for self-signed SSL certs to work
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }

$server = 'server.company.com'
$url = "https://${server}:8089/services/search/jobs/export" # braces needed b/c the colon is otherwise a scope operator
$search = "search index=_internal | stats count by sourcetype" # Cmdlet handles urlencoding
$body = @{
    search = $search
    output_mode = "json"
    earliest_time = "rt-5m"
    latest_time = "rt"
}
Invoke-RestMethod -Method Post -Uri $url -Credential $cred -Body $body

以上是关于powershell Splunk使用PowerShell导出搜索作业的主要内容,如果未能解决你的问题,请参考以下文章

PowerShell 添加任务以使用参数运行 PowerShell 脚本

如何使用 Python 中的参数运行 PowerShell 脚本

CentOS 7 上面安装PowerShell

在Powershell中,如何设置$?不将此值发送到管道?

win10 powershell禁止运行脚本解决

PowerShell小技巧:通过 PowerShell实现日志关键字分析