Skip to content

Instantly share code, notes, and snippets.

@bvierra
Created January 25, 2026 04:04
Show Gist options
  • Select an option

  • Save bvierra/aa5b484f1efd06ad5d187626aef5aa87 to your computer and use it in GitHub Desktop.

Select an option

Save bvierra/aa5b484f1efd06ad5d187626aef5aa87 to your computer and use it in GitHub Desktop.
function Test-NetConnectionUDP {
[CmdletBinding()]
param (
# Desit
[Parameter(Mandatory = $true)]
[int32]$Port,
# Parameter help description
[Parameter(Mandatory = $true)]
[string]$ComputerName,
# Parameter help description
[Parameter(Mandatory = $false)]
[int32]$SourcePort = 50000
)
begin {
# Create a UDP client object
$UdpObject = New-Object system.Net.Sockets.Udpclient($SourcePort)
# Define connect parameters
$UdpObject.Connect($ComputerName, $Port)
}
process {
# Convert current time string to byte array
$ASCIIEncoding = New-Object System.Text.ASCIIEncoding
$Bytes = $ASCIIEncoding.GetBytes("$(Get-Date -UFormat "%Y-%m-%d %T")")
# Send data to server
[void]$UdpObject.Send($Bytes, $Bytes.length)
}
end {
# Cleanup
$UdpObject.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment