YZlat
asked on
how to ping a computer using Powershell
I need to ping a computer using Powershell to determine whether a computer exists with a particular computer name.
I tried:
but it gives me an error:
Exception calling "Send" with "1" argument(s): "Value cannot be null.
Parameter name: address"
I tried:
$ping = new-object system.net.networkinformation.ping
$ret=$ping.send($entry)
but it gives me an error:
Exception calling "Send" with "1" argument(s): "Value cannot be null.
Parameter name: address"
Where are you declaring $entry?
why don't you try straight 'ping' command with computer name.
ping <computer name>
ping <computer name>
If you are using PowerShell 2.0 you should use Test-Connection instead of System.Net.NetworkInformat ion.Ping
Follow this link.
http://www.ilovepowershell.com/powershell-how-to-ping-computers/
Follow this link.
http://www.ilovepowershell.com/powershell-how-to-ping-computers/
$ping = new-object system.net.networkinformat ion.ping
$ret=$ping.send("<computer name or ip address>")
may be it will help you
http://www.ilovepowershell.com/powershell-how-to-ping-computers/
$ret=$ping.send("<computer
may be it will help you
http://www.ilovepowershell.com/powershell-how-to-ping-computers/
ASKER
ven16, if I use ping command, how do I retrieve the results?
ASKER
ven16, do you realize that your last comment is identical to the code I posted?
yes,i do just put the computername in brackets, i just add the computer name to your code.
sorry it was again wrong code ....
sorry it was again wrong code ....
ASKER
I tried Test-Connection and it seems to work, but what I really need is to return an error if the computer name cannot be found.
PING-EE-WORKS.Export.txt
This is a form based on a list of computers stored in the default path in the textbox. "C:\computers.txt" Or just create a text file on the C:\ drive named computers.txt from active directory. the results will be in green for computers connected and in red for those disconnected.
-R3c0n
This is a form based on a list of computers stored in the default path in the textbox. "C:\computers.txt" Or just create a text file on the C:\ drive named computers.txt from active directory. the results will be in green for computers connected and in red for those disconnected.
-R3c0n
Yea forgot to tell you to open it with powershell or rename it with a .ps1 extension using quotes "MyPingScriptForm.ps1"
Try this:
Test-Connection -ComputerName ComputerNameYouWantToPing -Quiet -Count 1
You'll get true or false response.
Just a quick update or step by step if your new to forms and powershell.
1.) If you exported your computers from active directory and saved only the computernames in a text file. You would then click the UPDATE button,
2.) Then highlight one of the computernames in the listbox. Click the GET INFO button and in the background test connection will run on the machine highlighted returning the results in the rich text box.
3.) You can save the results or look in the script I think I hard coded the results to a servers.rtf file on the C:\ drive. But it returns green for good and red for bad in the RTF box. I've been wanting to get this out for people to work with. Let me know how it works for everyone. Just trying to give back to the community.
-R3c0n
1.) If you exported your computers from active directory and saved only the computernames in a text file. You would then click the UPDATE button,
2.) Then highlight one of the computernames in the listbox. Click the GET INFO button and in the background test connection will run on the machine highlighted returning the results in the rich text box.
3.) You can save the results or look in the script I think I hard coded the results to a servers.rtf file on the C:\ drive. But it returns green for good and red for bad in the RTF box. I've been wanting to get this out for people to work with. Let me know how it works for everyone. Just trying to give back to the community.
-R3c0n
ASKER
That's not really what I need. I am already getting true or false response whether the computer is online. I want to get more detailed response as to why computer is unavailable. What I need is to find out which ones are ghost computers that do not exist. The name might be in AD but the machine does not exist. That's what I am looking for. Can anyone help?
Off the top of my head, sounds like you want to query AD for some properties of the object. If you have the Quest Active Directory tools installed, use:
If you don't have the QAD tools, I suggest you go download them. :)
get-qadcomputer {name} | Select whenChanged
That will (essentially) tell you the last time to computer talked with AD.If you don't have the QAD tools, I suggest you go download them. :)
ASKER
But that does not tell me whether the machine exists
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.