#requires -version 2.0 <# ----------------------------------------------------------------------------- Script: Get-IpconfigDNS.ps1 Version: 1.0 Author: Jeffery Hicks http://jdhitsolutions.com/blog http://twitter.com/JeffHicks http://www.ScriptingGeek.com Date: 11/14/2011 Keywords: Comments: "Those who forget to script are doomed to repeat their work." **************************************************************** * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED * * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK. IF * * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, * * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING. * **************************************************************** ----------------------------------------------------------------------------- #> [cmdletbinding()] Param() Write-Verbose "Getting DNS cache information" #parse dns data looking only for "Record" followed by a space $data=ipconfig /displaydns | select-string "Record " Write-Verbose ("Retrieved {0} entries" -f $data.count) Write-Verbose ("There should be {0} dns records" -f ($data.count/3)) #should be grouped into 3s. for ($i=0;$i -lt $data.count;$i+=3) { Write-Verbose $data[$i] #each item is a Match object so convert to string, split at colon, #grab the last item and trim it up. Cast the Type as an integer #so it sorts properly New-Object -TypeName PSobject -Property @{ Name=$data[$i].toString().Split(":")[1].Trim() Type=($data[$i+1].toString().Split(":")[1].Trim()) -as [int] Value=$data[$i+2].toString().Split(":")[1].Trim() } } #for Write-Verbose "Finished parsing DNS cache data"