SendToRsyslogTCP.ps1
#SendToRsyslogTCP.ps1
#sende eine Nachricht an den RSYSlogserver mit tcp / richard / 2019
[string]$message = "test"
[string]$buffer="<28>1 $(Get-Date -Format "yyyy-MM-ddTHH:mm:ssK") $env:computername windows - - -  $message"
 
$buffer
 
###############################################
Function SendtoRsyslogsrv([string]$remotesrv,[string]$buffer)
{
   [int]$port=514              
 
   $t = New-Object Net.Sockets.TcpClient
   try    { $t.Connect($remotesrv,$port) } 
   catch { "Fehler !"}
 
   if($t.Connected)
    {
        $DataStream = $t.GetStream()
        $Data = [text.Encoding]::Ascii.GetBytes($Buffer)    
        $DataStream.Write($Data,0,$Data.length)
        $t.Close()
        $t.Dispose()
        #$msg = "Port $port is open"
    }
    else
    {  $msg = "Port $port on $remotesrv is closed." }
    $msg
}
SendtoRsyslogsrv "192.168.1.234" $buffer