<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to send logs in Windows in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-to-send-logs-in-Windows/m-p/693447#M11596</link>
    <description>&lt;P&gt;1. It's more of a PowerShell question than a Splunk one.&lt;/P&gt;&lt;P&gt;2. For simple file monitoring it's easier to use UF (or other solutions capable of writing to a HEC endpoint if you find UF "too big" or "too closed source").&lt;/P&gt;&lt;P&gt;3. You haven't even told us at which point this error is raised.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jul 2024 09:02:51 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2024-07-16T09:02:51Z</dc:date>
    <item>
      <title>How to send logs in Windows</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-send-logs-in-Windows/m-p/693444#M11595</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to send logs my Windows server to Splunk via Powershell but I have this type of error :&amp;nbsp;&amp;nbsp; &lt;FONT color="#FF0000"&gt;Cannot convert value to type System.String.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;This is my code :&lt;/P&gt;&lt;P&gt;# Function to send log files with HEC&lt;BR /&gt;&lt;FONT color="#008000"&gt;function Send-LogToSplunk {&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;param (&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;[string]$filePath&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;$logContent = Get-Content -Path $filePath -Raw&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;$fileName = [System.IO.Path]::GetFileName($filePath)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;$fileDirectory = [System.IO.Path]::GetDirectoryName($filePath)&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;$splunkServer = "$splunkHost/services/collector/event"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;$header = @{"Authorization" = "Splunk $splunkToken"}&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;$payload = @{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;event = $logContent&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;host = $env:COMPUTERNAME&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;sourcetype = "log"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;source = $filePath&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;} | ConvertTo-Json&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;#Write-Host "Log Content $logContent";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;#Write-Host "Payload to be sent: $payload";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;Write-Host "FileDirectory $fileDirectory";&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;try {&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;$response = Invoke-RestMethod -Method Post -Uri $splunkServer -Headers $header -Body $payload&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;Write-Host "Log sent successfully: $fileName"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;} catch {&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;Write-Host "Failed to send log: $filePath Code Error: '$global:errorConnectionCode'"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;Write-Host "Error details: $_"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;Exit $global:errorConnectionCode&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;}&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;}&lt;/FONT&gt;&lt;FONT color="#339966"&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 07:39:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-send-logs-in-Windows/m-p/693444#M11595</guid>
      <dc:creator>bee</dc:creator>
      <dc:date>2024-07-16T07:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to send logs in Windows</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-send-logs-in-Windows/m-p/693447#M11596</link>
      <description>&lt;P&gt;1. It's more of a PowerShell question than a Splunk one.&lt;/P&gt;&lt;P&gt;2. For simple file monitoring it's easier to use UF (or other solutions capable of writing to a HEC endpoint if you find UF "too big" or "too closed source").&lt;/P&gt;&lt;P&gt;3. You haven't even told us at which point this error is raised.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 09:02:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-send-logs-in-Windows/m-p/693447#M11596</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-07-16T09:02:51Z</dc:date>
    </item>
  </channel>
</rss>

