Created
June 25, 2018 16:43
-
-
Save guitarrapc/9211234c8d25321b0f9e9d661d5c6309 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$user ="Input UserName" | |
$credential = Get-SumoCredential -User $user -force | |
$Collectors = Get-SumoApiCollectors -Credential $credential | |
$sets = @( | |
("LogName","LogPath","Desctiption"), | |
("LogName","LogPath","Desctiption") | |
) | |
$jsons = $sets ` | |
| %{ @{ | |
source = @{ | |
pathExpression = $_[1] | |
name = $_[0] | |
sourceType = "LocalFile" | |
category = $_[0] | |
description = $_[2] | |
alive = $true | |
states = "" | |
automaticDateParsing = $true | |
timeZonne = "Asia/Tokyo" | |
multilineProcessingEnabled = $true | |
}} ` | ConvertTo-Json | |
} | |
$osName = "Windows Server 2012" | |
$name = "hogehoge*" | |
$collectors ` | |
| where osName -eq $osName ` | |
| where Name -like $name ` | |
| %{ | |
try | |
{ | |
foreach ($json in $jsons) | |
{ | |
Invoke-RestMethod -Method Post -Uri "https://api.sumologic.com/api/v1/collectors/$($_.id)/sources/" -Credential $cred -ContentType "application/json" -Body $json -ErrorAction Stop | |
} | |
} | |
catch | |
{ | |
throw $_ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment