perform nslookup from PowerShell

夙愿已清 提交于 2019-12-06 13:31:31

问题


I'm writing a powershell to exact the ip from a server name, which need me to embed the nslookup code into my powershell

how can I do the intergrating work?

Can any body help me?

Add-PSSnapin Microsoft.SharePoint.PowerShell
$web = Get-SPWeb -Identity “http://nycs00058260/sites/usitp“
$server_status = "PROD"
$list=$web.Lists[”DNS_Status”]
$items = $list.items 
Foreach($item in $items){
    $item_name = $item["Server_name"]  #need to get the ip by this name

    /*nslook up*/
     $item_name.update()

}

回答1:


If you install the PSCX module, it comes with a cmdlet Resolve-Host which handles name lookups.

Absent that, this one-liner will do the job

[System.Net.Dns]::GetHostAddresses("www.msn.com")

You can also pass in an IP address - but the results will be different.

See also http://blogs.msdn.com/b/powershell/archive/2006/06/26/647318.aspx & http://powershell.com/cs/media/p/210.aspx




回答2:


PowerShell 3.0 on Windows 8 and higher comes with a Resolve-DnsName cmdlet that will get this information:

(Resolve-DnsName $server_name)[0].IpAddress



回答3:


Simply use :

Resolve-DnsName monServer | ? { # make selection here } | % { $_.IPAdress }  | select-object -first 1


来源:https://stackoverflow.com/questions/12394552/perform-nslookup-from-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!