header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Ip + Name
Last Post 06 Jul 2008 08:39 PM by bsonposh. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
SelgaldUser is Offline
New Member
New Member
Posts:1
Avatar

--
03 Jul 2008 08:57 AM  

Hello,

iam new here, and iam new to powershell :)

this is my first try:

I want to ping some Ip's or Host's from a textfile

 

Get-Content C:\Ping2.txt | Ping-Host -Timeout 1 -Count 1 -BufferSize 1 | Format-Table | Out-File C:\Test.txt

with this script, it looks like this:

 

Host                                                                                            Loss  Sent  Received AverageTime
----                                                                                                ----  ----  -------- -----------
abc.xxx.xxx.de                                                                             0 %   1     1        1ms      

 

but I also need the IP :

 

Host                         IP                                                                Loss  Sent  Received AverageTime
----                            ----                                                                    ----  ----  -------- -----------
abc.xxx.xxx.de                                                                             0 %   1     1        1ms       

 

but all my trys wont work :(

can you guys help me?

bsonposhUser is Offline
Basic Member
Basic Member
Posts:392
Avatar

--
03 Jul 2008 02:52 PM  
While a tad convoluted. You can use calculated properties for this.

More Info on Calculated Properties Here
http://bsonposh.com/archives/260
http://bsonposh.com/archives/262

$myIP   = @{l="IP";e={[system.Net.Dns]::Resolve($_.HostName).AddressList[ 0 ].IPAddressToString}}
$myhost = @{l="HostName";e={[system.Net.Dns]::Resolve($_.HostName).HostName}}
Get-Content C:\Ping2.txt | Ping-Host -Timeout 1 -Count 1 -BufferSize 1  | ft $myHost,$MyIP,Loss,Sent,'Received AverageTime'


Effectively this uses system.Net.Dns to resolve the HostName to IP and vise-versa so you can have both IPs and Hostnames and as long as DNS is setup you should end up with your goal.
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
glnsizeUser is Online
Basic Member
Basic Member
Posts:101

--
06 Jul 2008 08:24 PM  

 

@Selgald,  If you haven't figured it out already Ping-Host is a cmdlet in the PowerShell Community Extensions PSSnapin.

http://www.codeplex.com/PowerShellCX/Release/ProjectReleases.aspx?ReleaseId=2688

@bsonposh, I'm green with envy... It took me years to get to know my way around WMI.  Now I'm a noob with all these .net classes. You sir are my idol of the week.

~Glenn

bsonposhUser is Offline
Basic Member
Basic Member
Posts:392
Avatar

--
06 Jul 2008 08:39 PM  
Wow... a whole week? I was only looking for 15mins :)
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer