This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Send syslog using PowerShell

There was a need to send out syslogs to Orion through DMZ.  The "Kiwi Syslog message generator" did not work, so found a portable way to do this using powershell.   This is a well known script, just had to tweak the date format so that SW syslog understood it.

pastedImage_0.png

$Server = 'x.x.x.x'

$Message = 'From  - PowerShell'

#0=EMERG 1=Alert 2=CRIT 3=ERR 4=WARNING 5=NOTICE  6=INFO  7=DEBUG

$Severity = '1'

#(16-23)=LOCAL0-LOCAL7

$Facility = '22'

$Hostname= 'Test-DC01'

# Create a UDP Client Object

$UDPCLient = New-Object System.Net.Sockets.UdpClient

$UDPCLient.Connect($Server, 514)

# Calculate the priority

$Priority = ([int]$Facility * 8) + [int]$Severity

#Time format the SW syslog understands

$Timestamp = Get-Date -Format "MMM dd HH:mm:ss"

# Assemble the full syslog formatted message

$FullSyslogMessage = "<{0}>{1} {2} {3}" -f $Priority, $Timestamp, $Hostname, $Message

# create an ASCII Encoding object

$Encoding = [System.Text.Encoding]::ASCII

# Convert into byte array representation

$ByteSyslogMessage = $Encoding.GetBytes($FullSyslogMessage)

# Send the Message

$UDPCLient.Send($ByteSyslogMessage, $ByteSyslogMessage.Length)

I used this to show the client that the syslogs were actually blocked by the DMZ firewall by running the PowerShell on different subnets.  The good part is that no software installation is needed.

Thanks

Amit