Data On Demand GetDnsClientCache write action

Community.DataOnDemand.WriteAction.GetDnsClientCache (WriteActionModuleType)

Displays the contents of the DNS client cache on windows.

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
InputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
WA WriteAction Microsoft.Windows.PowerShellWriteAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Timeout (Seconds)Script timeout in seconds
Formatstring$Config/Format$Output formatAllowed values: csv, json, text

Source Code:

<WriteActionModuleType ID="Community.DataOnDemand.WriteAction.GetDnsClientCache" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Format" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="Format" Selector="$Config/Format$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>Get-DnsClientCache.ps1</ScriptName>
<ScriptBody><Script>&lt;#
.SYNOPSIS
Community.DataOnDemand DNS cache script
.DESCRIPTION
This script enumerates the DNS cache and outputs formatted text
.PARAMETER Format
Permitted values: text, csv, json
.NOTES
Copyright 2016 Squared Up Limited, All Rights Reserved.
#&gt;
Param(
[ValidateSet("text","csv","json", "list")]
[string] $Format = "csv"
)

#Requires -Version 2.0
Set-StrictMode -Version 2.0
$ErrorActionPreference = "stop"

function Get-DNSRecordType
{
Param([uint16]$type)
switch ($type)
{
1 { return "A" }
2 { return "NS" }
5 { return "CNAME" }
6 { return "SOA" }
12 { return "PTR" }
15 { return "MX" }
28 { return "AAAA" }
33 { return "SRV" }
default { return "$type" }
}
}

#Execute the underlying PS
$OutputObjects = @(Get-DnsClientCache)

if ($Format -eq 'text')
{
$OutputObjects `
| Select-Object Entry, Name, @{N='RecordType';E={Get-DNSRecordType $_.Type}}, Data `
| Format-Table -AutoSize `
| Out-String -Width 4096 `
| Write-Host
}
elseif ($Format -eq 'csv')
{
$OutputObjects `
| convertto-csv -NoTypeInformation `
| Out-String -Width 4096 `
| Write-Host
}
elseif ($Format -eq 'json')
{
$OutputObjects `
| convertto-json `
| Out-String -Width 4096 `
| Write-Host
}
elseif ($format -eq 'list')
{
$OutputObjects `
| Select-Object Entry, Name, @{N='RecordType';E={Get-DNSRecordType $_.Type}}, Data `
| Format-List `
| Out-String -Width 4096 `
| Write-Host
}

# Done. (do not remove blank line following this comment as it can cause problems when script is sent to SCOM agent!)
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>Format</Name>
<Value>$Config/Format$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="WA"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>