从PowerShell执行nslookup [英] perform nslookup from PowerShell
问题描述
我正在编写一个Powershell来从服务器名称中提取IP,这需要我将nslookup代码嵌入到我的Powershell中
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?
有人可以帮助我吗?
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()
}
推荐答案
如果安装 PSCX 模块,它带有一个处理名称查找的cmdlet Resolve-Host
.
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")
您也可以输入IP地址-但结果会有所不同.
You can also pass in an IP address - but the results will be different.
另请参见 http://blogs.msdn. com/b/powershell/archive/2006/06/26/647318.aspx & http://powershell.com/cs/media/p/210.aspx
See also http://blogs.msdn.com/b/powershell/archive/2006/06/26/647318.aspx & http://powershell.com/cs/media/p/210.aspx
这篇关于从PowerShell执行nslookup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!