Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #requires -version 3.0
- Function Get-IPConfigDNS {
- [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 MatchInfo 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.
- [ordered] is a v3 feature. Remove it if you want this to run in
- PowerShell v2
- #>
- $hash = [ordered]@{
- 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()
- }
- #create a new object from the hash table and write it to the pipeline
- New-Object -TypeName PSobject -Property $hash
- } #for
- Write-Verbose "Finished parsing DNS cache data"
- } #end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement