$serverIP = "127.0.0.1" # Replace with the IP address or hostname of the server $port = 80 # Replace with the port number you want to connect to # Create a TCP client object $client = New-Object System.Net.Sockets.TcpClient # Connect to the server $client.Connect($serverIP, $port) if ($client.Connected) { Write-Host "Connected to $serverIP on port $port" # Do further operations with the connection if required # Close the connection $client.Close() } else { Write-Host "Connection failed" }