forked from jajp777/powershell-scripts-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-DnsClientCache.ps1
55 lines (34 loc) · 1.51 KB
/
Get-DnsClientCache.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function Get-DnsClientCache {
[CmdletBinding()]
param (
[string]
$IpConfigPath = 'C:\Windows\System32\ipconfig.exe',
[string]
$IpConfigArgs = '/displaydns',
[string]
$TempFile = (Join-Path -Path $env:TEMP -ChildPath $(([System.Guid]::NewGuid().Guid) + '.txt'))
) #param
process {
$SplatArgs = @{ FilePath = $IpConfigPath
ArgumentList = $IpConfigArgs
NoNewWindow = $true
Wait = $true
RedirectStandardOutput = $TempFile }
Start-Process @SplatArgs
$IpConfigOutput = Get-Content -Path $TempFile
Remove-Item -Path $TempFile | Out-Null
$DnsClientCache = @()
$IpConfigOutput | Select-String -Pattern "Record Name" -Context 0,5 | ForEach-Object {
$Record = New-Object -TypeName psobject -Property @{
Name = (($_.Line -split ':')[1]).Trim()
Type = (($_.Context.PostContext[0] -split ':')[1]).Trim()
TTL = (($_.Context.PostContext[1] -split ':')[1]).Trim()
Length = (($_.Context.PostContext[2] -split ':')[1]).Trim()
Section = (($_.Context.PostContext[3] -split ':')[1]).Trim()
HostRecord = (($_.Context.PostContext[4] -split ':')[1]).Trim()
} #New-Object
$DnsClientCache += $Record
} #ForEach
Write-Output -InputObject $DnsClientCache
} #process
} #function Get-DnsClientCache