Advertisement
Guest User

Get-IPConfigDNS

a guest
Jul 31st, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. #requires -version 3.0
  2.  
  3. Function Get-IPConfigDNS {
  4.  
  5. [cmdletbinding()]
  6. Param()
  7.  
  8. Write-Verbose "Getting DNS cache information"
  9. #parse dns data looking only for "Record" followed by a space
  10. $data=ipconfig /displaydns | select-string "Record "
  11.  
  12. Write-Verbose ("Retrieved {0} entries" -f $data.count)
  13. Write-Verbose ("There should be {0} dns records" -f ($data.count/3))
  14.  
  15. #should be grouped into 3s.
  16. for ($i=0;$i -lt $data.count;$i+=3) {
  17.     Write-Verbose $data[$i]
  18.    
  19.     <#
  20.      each item is a MatchInfo object so convert to string, split at colon,
  21.      grab the last item and trim it up. Cast the Type as an integer
  22.      so it sorts properly.
  23.      [ordered] is a v3 feature. Remove it if you want this to run in
  24.      PowerShell v2
  25.     #>
  26.  
  27.     $hash = [ordered]@{
  28.       Name=$data[$i].toString().Split(":")[1].Trim()
  29.       Type=($data[$i+1].toString().Split(":")[1].Trim()) -as [int]
  30.       Value=$data[$i+2].toString().Split(":")[1].Trim()
  31.     }
  32.     #create a new object from the hash table and write it to the pipeline
  33.     New-Object -TypeName PSobject -Property $hash
  34. } #for
  35.  
  36. Write-Verbose "Finished parsing DNS cache data"
  37. } #end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement