diff --git a/MyScripts/Bootstrap-RemoteHostViaSSH.ps1 b/MyScripts/Bootstrap-RemoteHostViaSSH.ps1 index 164b262..b5fea3f 100644 --- a/MyScripts/Bootstrap-RemoteHostViaSSH.ps1 +++ b/MyScripts/Bootstrap-RemoteHostViaSSH.ps1 @@ -333,3 +333,21 @@ $PromptSSParams = @{ RemovePwdFile = $False } $UserString = Prompt-ActiveUserForSecureString @PromptSSParams + +# Scan network for Printers +$printers = 1..254 | ForEach-Object { + $ip = "192.168.5.$_" + $tcpClient = New-Object System.Net.Sockets.TcpClient + $result = $tcpClient.BeginConnect($ip, 9100, $null, $null) + + if ($result.AsyncWaitHandle.WaitOne(1000, $false) -and $tcpClient.Connected) { + $tcpClient.Close() + [PSCustomObject]@{ + IP = $ip + Status = 'Printer Found' + } + } else { + $tcpClient.Close() + $null + } +} | Where-Object { $_.Status -eq 'Printer Found' }