Advertisement
irelephant

Untitled

May 16th, 2024
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. param (
  2. [string]$ipAddress,
  3. [string]$message
  4. )
  5.  
  6. # Function to check if a computer is online
  7. function Test-ComputerOnline {
  8. param (
  9. [string]$ipAddress
  10. )
  11. $ping = Test-Connection -ComputerName $ipAddress -Count 1 -Quiet
  12. return $ping
  13. }
  14.  
  15. # Check if the target IP is online
  16. if (Test-ComputerOnline -ipAddress $ipAddress) {
  17. try {
  18. msg.exe * /server:$ipAddress $message
  19. Write-Output "Message sent to $ipAddress"
  20. } catch {
  21. Write-Output "Failed to send message to $ipAddress"
  22. }
  23. } else {
  24. Write-Output "$ipAddress is not online"
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement