Servidor escucha y ejecuta los credenciales
1 2 3 4 5 6 7 8 9 |
$port=2022 $endpoint = new-object System.Net.IPEndPoint ([IPAddress]::Any,$port) $udpclient=new-Object System.Net.Sockets.UdpClient $port $content=$udpclient.Receive([ref]$endpoint) # Ejecutar los credenciales que llegan por UDP $jsonc = [Text.Encoding]::ASCII.GetString($content) | ConvertFrom-Json $cred = New-Object -TypeName PSCredential $jsonc.UserName,($jsonc.Password | ConvertTo-SecureString) Start-Process notepad -Credential $cred |

Cliente manda los credenciales
1 2 3 4 5 6 7 8 9 10 |
# Almacenar credenciales en un fichero JSON Get-Credential | Select Username,@{n="Password"; e={$_.password | ConvertFrom-SecureString}} | ConvertTo-Json | Set-Content -Path credenciales.json -Encoding UTF8 $port=2022 $endpoint = new-object System.Net.IPEndPoint ([IPAddress]::Loopback,$port) $udpclient=new-Object System.Net.Sockets.UdpClient $val = Get-Content -Path .\credenciales.json -Encoding UTF8 -Raw $b=[Text.Encoding]::ASCII.GetBytes($val.ToString()) $bytesSent=$udpclient.Send($b,$b.length,$endpoint) $udpclient.Close() |
