Sunday 19 April 2009

Get-HostEntry.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Demonstrates use of the GetHostEntry method of System.Net.DNS Class 
  4. .DESCRIPTION 
  5.     This script is a an MSDN sample, using PowerShell 
  6. .NOTES 
  7.     File Name  : Get-HostEntry.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell V2 CTP3 
  10. .LINK 
  11.     Sample posted to: 
  12.     http://pshscripts.blogspot.com/2009/04/get-hostentryps1.html 
  13.     Original MSDN sample at: 
  14.     http://msdn.microsoft.com/en-us/library/system.net.dns.gethostentry.aspx  
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\Get-HostEntry.ps1 Cookham8
  17.     Host Name    : Cookham8.cookham.net 
  18.     Alias        : 
  19.     Address      : fe80::d8ed:afe2:2a97:a596%14 
  20.     Address      : fe80::3953:f67b:2f1c:1323%10 
  21.     Address      : 10.10.1.120 
  22.     Address      : 10.10.1.115 
  23. .PARAM HostName 
  24.     The name of the host to search for - the default is "localhost" 
  25. #> 
  26.  
  27. param
  28. [string] $HostName = "localhost" 
  29.  
  30. ### 
  31. # Start of Script 
  32. ### 
  33.   
  34. #Get Host details 
  35.  
  36. $hostentrydetails = [System.Net.Dns]::GetHostEntry($hostname
  37.  
  38. # Print details: 
  39. "Host Name    : {0}" -f $hostentrydetails.HostName 
  40. foreach ($alias in $hostentrydetails.alises) { 
  41. "Alias        : {0}" -f $alias 
  42. foreach ($addr in $hostentrydetails.addresslist) { 
  43. "Address      : {0}" -f $Addr.ipaddresstostring 
  44.   
  45. # End of script 

4 comments:

arnold said...

hello sir

i have PS v2 (CPT.)

but Get-HostEntry.ps1 is not run ?
do you way?
tnx for help
arnold

The term 'param' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.
à :ligne:27 caractère:5
+ param <<<< ( '''

Thomas Lee said...

Arnold,

Do you have CTP3 loaded? I think that might be your trouble.

How did you get the script onto your system? Did you get it from th ZIP file?

For what it is worth, this works fine here.

arnold said...

Hi thomas :)
Nice to see you.

Yep, i have CPT3,(i loos the 3 befor) is loadet
and i dont see any zypfile :(
only i make copy/past to
importet the file to PowerGUI.

I find you with google :
"powershell convert rssfeed to html"
"PoSh Automaten Host"

Tnx for you answear
arnold

Thomas Lee said...

Arnold - the script works fine here. I suspect you may have gotten some garbage characters when you copied over the script.

Try downloading the entire script library from http://www.reskit.net/powershell/ScriptLib.ZIP. It's only just over 100k, and has all the scripts. Try that and let me know.

And for more help email me at doctordns {at} gmail {dot} com.