Skip to content

Instantly share code, notes, and snippets.

@indented-automation
Created July 21, 2022 14:30
Show Gist options
  • Save indented-automation/25e5f821a97f4e0022a2f3e3602b5616 to your computer and use it in GitHub Desktop.
Save indented-automation/25e5f821a97f4e0022a2f3e3602b5616 to your computer and use it in GitHub Desktop.
This is a mess. Needs major refactoring.
##############################################################################################################################################################
# IANA #
##############################################################################################################################################################
#
# Address family
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.IanaAddressFamily" -Type "UInt16" -Members @{
IPv4 = 1; # IP version 4
IPv6 = 2; # IP version 6
NSAP = 3; # NSAP
HDLC = 4; # HDLC (8-bit multidrop)
BBN = 5; # BBN 1822
"802" = 6; # 802 (includes all 802 media plus Ethernet "canonical format")
"E.163" = 7; # E.163
"E.164" = 8; # E.164 (SMDS, Frame Relay, ATM)
"F.69" = 9; # F.69 (Telex)
"X.121" = 10; # X.121 (X.25, Frame Relay)
IPX = 11; # IPX
Appletalk = 12; # Appletalk
DecNetIV = 13; # DecNet IV
BanyanVines = 14; # Banyan Vines
"E.164NSAP" = 15; # E.164 with NSAP format subaddress [ATM Forum UNI 3.1. October 1995.][Andy_Malis]
DNS = 16; # DNS (Domain Name System)
DistinguishedName = 17; # Distinguished Name [Charles_Lynn]
ASNumber = 18; # AS Number [Charles_Lynn]
XTPOverIpv4 = 19; # XTP over IP version 4 [Mike_Saul]
XTPOverIPv6 = 20; # XTP over IP version 6 [Mike_Saul]
XTPNativeMode = 21; # XTP native mode XTP [Mike_Saul]
FibreChannelWWPortName = 22; # Fibre Channel World-Wide Port Name [Mark_Bakke]
FibreChannelWWNodeName = 23; # Fibre Channel World-Wide Node Name [Mark_Bakke]
GWID = 24; # GWID [Subra_Hegde]
AFIForL2VPN = 25; # AFI for L2VPN information [RFC4761][RFC6074]
MPLSTPSectionID = 26; # MPLS-TP Section Endpoint Identifier [RFC-ietf-mpls-gach-adv-08]
MPLSTPLSPID = 27; # MPLS-TP LSP Endpoint Identifier [RFC-ietf-mpls-gach-adv-08]
MPLSTPPseudowireID = 28; # MPLS-TP Pseudowire Endpoint Identifier [RFC-ietf-mpls-gach-adv-08]
EIGRPCommon = 16384; # EIGRP Common Service Family [Donnie_Savage]
EIGRPIPv4 = 16385; # EIGRP IPv4 Service Family [Donnie_Savage]
EIGRPIPv6 = 16386; # EIGRP IPv6 Service Family [Donnie_Savage]
LCAF = 16387; # LISP Canonical Address Format (LCAF) [David_Meyer]
BGPLS = 16388; # BGP-LS [draft-ietf-idr-ls-distribution]
MAC48bit = 16389; # 48-bit MAC [RFC-eastlake-rfc5342bis-05]
MAC64bit = 16390; # 64-bit MAC [RFC-eastlake-rfc5342bis-05]
OUI = 16391; # OUI [draft-eastlake-trill-ia-appsubtlv]
MAC24 = 16392; # MAC/24 [draft-eastlake-trill-ia-appsubtlv]
MAC40 = 16393; # MAC/40 [draft-eastlake-trill-ia-appsubtlv]
"IPv6-64" = 16394; # IPv6/64 [draft-eastlake-trill-ia-appsubtlv]
RBridgePortID = 16395; # RBridge Port ID [draft-eastlake-trill-ia-appsubtlv]
}
#
# Certificate types
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.CertificateType" -Type "UInt16" -Members @{
PKIX = 1; # X.509 as per PKIX
SPKI = 2; # SPKI certificate
PGP = 3; # OpenPGP packet
IPKIX = 4; # The URL of an X.509 data object
ISPKI = 5; # The URL of an SPKI certificate
IPGP = 6; # The fingerprint and URL of an OpenPGP packet
ACPKIX = 7; # Attribute Certificate
IACPKIX = 8; # The URL of an Attribute Certificate
URI = 253; # URI private
OID = 254; # OID private
}
#
# Digest types
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.DigestType" -Type "Byte" -Members @{
SHA1 = 1; # MANDATORY [RFC3658]
SHA256 = 2; # MANDATORY [RFC4059]
GOST = 3; # OPTIONAL [RFC5933]
SHA384 = 4; # OPTIONAL [RFC6605]
}
#
# Encryption algorithm
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.EncryptionAlgorithm" -Type "Byte" -Members @{
RSAMD5 = 1; # RSA/MD5 (deprecated, see 5) [RFC3110][RFC4034]
DH = 2; # Diffie-Hellman [RFC2539]
DSA = 3; # DSA/SHA1 [RFC3755]
RSASHA1 = 5; # RSA/SHA-1 [RFC3110][RFC4034]
"DSA-NSEC3-SHA1" = 6; # DSA-NSEC3-SHA1 [RFC5155]
"RSASHA1-NSEC3-SHA1" = 7; # RSASHA1-NSEC3-SHA1 [RFC5155]
RSASHA256 = 8; # RSA/SHA-256 [RFC5702]
RSASHA512 = 10; # RSA/SHA-512 [RFC5702]
"ECC-GOST" = 12; # GOST R 34.10-2001 [RFC5933]
ECDSAP256SHA256 = 13; # ECDSA Curve P-256 with SHA-256 [RFC6605]
ECDSAP384SHA384 = 14; # ECDSA Curve P-384 with SHA-384 [RFC6605]
INDIRECT = 252; # Reserved for indirect keys [RFC4034]
PRIVATEDNS = 253; # Private algorithm [RFC4034]
PRIVATEOID = 254; # Private algorithm OID [RFC4034]
}
#
# SSH algorithms
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.SSHAlgorithm" -Type "Byte" -Members @{
RSA = 1; # [RFC4255]
DSS = 2; # [RFC4255]
}
#
# SSH fingerprint type
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.SSHFPType" -Type "Byte" -Members @{
SHA1 = 1; # [RFC4255]
}
##############################################################################################################################################################
# RESOLVER PARAMETERS #
##############################################################################################################################################################
#
# Flags - Offset to allow direct parsing of a 16-bit unsigned value
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.Flags" -Type "UInt16" -SetFlagsAttribute -Members @{
None = 0;
AA = 1024; # Authoritative Answer [RFC1035]
TC = 512; # Truncated Response [RFC1035]
RD = 256; # Recursion Desired [RFC1035]
RA = 128; # Recursion Allowed [RFC1035]
AD = 32; # Authenticated Data [RFC4035]
CD = 16; # Checking Disabled [RFC4035]
}
#
# Message compression flag
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.MessageCompression" -Type "Byte" -Members @{
Enabled = 192;
Disabled = 0;
}
#
# MS XFR compression
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.MSDNSOption" -Type "UInt32" -Members @{
CompressXFR = 19795
}
#
# OpCode
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.OpCode" -Type "UInt16" -Members @{
Query = 0; # [RFC1035]
IQuery = 1; # [RFC3425]
Status = 2; # [RFC1035]
Notify = 4; # [RFC1996]
Update = 5; # [RFC2136]
}
#
# Query flag
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.QR" -Type "UInt16" -Members @{
Query = 0;
Response = 32768
}
#
# RecordClass
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.RecordClass" -Type "UInt16" -Members @{
IN = 1; # [RFC1035]
CH = 3; # [Moon1981]
HS = 4; # [Dyer1987]
NONE = 254; # [RFC2136]
ANY = 255; # [RFC1035]
}
#
# RecordType
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.RecordType" -Type "UInt16" -Members @{
EMPTY = 0; # an empty record [RFC1034] [MS DNS]
A = 1; # a host address [RFC1035]
NS = 2; # an authoritative name server [RFC1035]
MD = 3; # a mail destination (Obsolete - use MX) [RFC1035]
MF = 4; # a mail forwarder (Obsolete - use MX) [RFC1035]
CNAME = 5; # the canonical name for an alias [RFC1035]
SOA = 6; # marks the start of a zone of authority [RFC1035]
MB = 7; # a mailbox domain name (EXPERIMENTAL) [RFC1035]
MG = 8; # a mail group member (EXPERIMENTAL) [RFC1035]
MR = 9; # a mail rename domain name (EXPERIMENTAL) [RFC1035]
NULL = 10; # a null RR (EXPERIMENTAL) [RFC1035]
WKS = 11; # a well known service description [RFC1035]
PTR = 12; # a domain name pointer [RFC1035]
HINFO = 13; # host information [RFC1035]
MINFO = 14; # mailbox or mail list information [RFC1035]
MX = 15; # mail exchange [RFC1035]
TXT = 16; # text strings [RFC1035]
RP = 17; # for Responsible Person [RFC1183]
AFSDB = 18; # for AFS Data Base location [RFC1183]
X25 = 19; # for X.25 PSDN address [RFC1183]
ISDN = 20; # for ISDN address [RFC1183]
RT = 21; # for Route Through [RFC1183]
NSAP = 22; # for NSAP address; NSAP style A record [RFC1706]
NSAPPTR = 23; # for domain name pointer; NSAP style [RFC1348]
SIG = 24; # for security signature [RFC4034][RFC3755][RFC2535]
KEY = 25; # for security key [RFC4034][RFC3755][RFC2535]
PX = 26; # X.400 mail mapping information [RFC2163]
GPOS = 27; # Geographical Position [RFC1712]
AAAA = 28; # IP6 Address [RFC3596]
LOC = 29; # Location Information [RFC1876]
NXT = 30; # Next Domain - OBSOLETE [RFC3755][RFC2535]
EID = 31; # Endpoint Identifier [Patton]
NIMLOC = 32; # Nimrod Locator [Patton]
SRV = 33; # Server Selection [RFC2782]
ATMA = 34; # ATM Address [ATMDOC]
NAPTR = 35; # Naming Authority Pointer [RFC2915][RFC2168]
KX = 36; # Key Exchanger [RFC2230]
CERT = 37; # CERT [RFC4398]
A6 = 38; # A6 (Experimental) [RFC3226][RFC2874]
DNAME = 39; # DNAME [RFC2672]
SINK = 40; # SINK [Eastlake]
OPT = 41; # OPT [RFC2671]
APL = 42; # APL [RFC3123]
DS = 43; # Delegation Signer [RFC4034][RFC3658]
SSHFP = 44; # SSH Key Fingerprint [RFC4255]
IPSECKEY = 45; # IPSECKEY [RFC4025]
RRSIG = 46; # RRSIG [RFC4034][RFC3755]
NSEC = 47; # NSEC [RFC4034][RFC3755]
DNSKEY = 48; # DNSKEY [RFC4034][RFC3755]
DHCID = 49; # DHCID [RFC4701]
NSEC3 = 50; # NSEC3 [RFC5155]
NSEC3PARAM = 51; # NSEC3PARAM [RFC5155]
HIP = 55; # Host Identity Protocol [RFC5205]
NINFO = 56; # NINFO [Reid]
RKEY = 57; # RKEY [Reid]
SPF = 99; # [RFC4408]
UINFO = 100; # [IANA-Reserved]
UID = 101; # [IANA-Reserved]
GID = 102; # [IANA-Reserved]
UNSPEC = 103; # [IANA-Reserved]
TKEY = 249; # Transaction Key [RFC2930]
TSIG = 250; # Transaction Signature [RFC2845]
IXFR = 251; # incremental transfer [RFC1995]
AXFR = 252; # transfer of an entire zone [RFC1035]
MAILB = 253; # mailbox-related RRs (MB; MG or MR) [RFC1035]
MAILA = 254; # mail agent RRs (Obsolete - see MX) [RFC1035]
ANY = 255; # A request for all records (*) [RFC1035]
TA = 32768; # DNSSEC Trust Authorities [Weiler] 2005-12-13
DLV = 32769; # DNSSEC Lookaside Validation [RFC4431]
WINS = 65281; # WINS records (WINS Lookup record) [MS DNS]
WINSR = 65282; # WINSR records (WINS Reverse Lookup record) [MS DNS]
}
#
# RCode
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.RCode" -Type "UInt16" -Members @{
NoError = 0; # No Error [RFC1035]
FormErr = 1; # Format Error [RFC1035]
ServFail = 2; # Server Failure [RFC1035]
NXDomain = 3; # Non-Existent Domain [RFC1035]
NotImp = 4; # Not Implemented [RFC1035]
Refused = 5; # Query Refused [RFC1035]
YXDomain = 6; # Name Exists when it should not [RFC2136]
YXRRSet = 7; # RR Set Exists when it should not [RFC2136]
NXRRSet = 8; # RR Set that should exist does not [RFC2136]
NotAuth = 9; # Server Not Authoritative for zone [RFC2136]
NotZone = 10; # Name not contained in zone [RFC2136]
BadVers = 16; # Bad OPT Version [RFC2671]
BadSig = 16; # TSIG Signature Failure [RFC2845]
BadKey = 17; # Key not recognized [RFC2845]
BadTime = 18; # Signature out of time window [RFC2845]
BadMode = 19; # Bad TKEY Mode [RFC2930]
BadName = 20; # Duplicate key name [RFC2930]
BadAlg = 21; # Algorithm not supported [RFC2930]
BadTrunc = 22; # Bad Truncation [RFC4635]
}
##############################################################################################################################################################
# RESOLVER RECORD SPECIFIC PARAMETERS #
##############################################################################################################################################################
#
# AFSDB
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.AFSDBSubType" -Type "UInt16" -Members @{
AFSv3Loc = 1; # Andrews File Service v3.0 Location Service [RFC1183]
DCENCARoot = 2; # DCE/NCA root cell directory node [RFC1183]
}
#
# ATMA: Format
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.ATMAFormat" -Type "UInt16" -Members @{
AESA = 0; # ATM End System Address
E164 = 1; # E.164 address format
NSAP = 2; # Network Service Access Protocol (NSAP) address model
}
#
# IPSEC
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.IPSECGatewayType" -Type "Byte" -Members @{
NoGateway = 0; # No gateway is present [RFC4025]
IPv4 = 1; # A 4-byte IPv4 address is present [RFC4025]
IPv6 = 2; # A 16-byte IPv6 address is present [RFC4025]
DomainName = 3; # A wire-encoded domain name is present [RFC4025]
}
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.IPSECAlgorithm" -Type "Byte" -Members @{
DSA = 1; # [RFC4025]
RSA = 2; # [RFC4025]
}
#
# KEY: Flags
#
# Bits 1 and 2
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.KEYAC" -Type "Byte" -Members @{
AuthAndConfPermitted = 0; # Use of the key for authentication and/or confidentiality is permitted.
AuthProhibited = 2; # Use of the key is prohibited for authentication.
ConfProhibited = 1; # Use of the key is prohibited for confidentiality.
NoKey = 3; # No key information
}
# Bits 6 and 7
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.KEYNameType" -Type "Byte" -Members @{
UserKey = 0; # Indicates that this is a key associated with a "user" or "account" at an end entity, usually a host.
ZoneKey = 1; # Indicates that this is a zone key for the zone whose name is the KEY RR owner name.
NonZone = 2; # Indicates that this is a key associated with the non-zone "entity" whose name is the RR owner name.
Reserved = 3; # Reserved
}
#
# KEY: Protocol
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.KEYProtocol" -Type "Byte" -Members @{
Reserved = 0;
TLS = 1;
EMmail = 2;
DNSSEC = 3;
IPSEC = 4;
All = 255;
}
#
# OPT: EDNS option codes
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.EDnsOptionCode" -Type "UInt16" -Members @{
LLQ = 1; # On-hold [http://files.dns-sd.org/draft-sekar-dns-llq.txt]
UL = 2; # On-hold [http://files.dns-sd.org/draft-sekar-dns-ul.txt]
NSID = 3; # Standard [RFC5001]
DAU = 5; # Standard [RFC6975]
DHU = 6; # Standard [RFC6975]
N3U = 7; # Standard [RFC6975]
"EDNS-client-subnet" = 8; # Optional [draft-vandergaast-edns-client-subnet][Wilmer_van_der_Gaast]
}
#
# OPT: DNSSEC Validation flag
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.EDnsDNSSECOK" -Type "UInt16" -SetFlagsAttribute -Members @{
NONE = 0;
DO = 32768; # DNSSEC answer OK [RFC4035][RFC3225]
}
#
# OPT: LLQ
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.LLQOpCode" -Type "UInt16" -Members @{
LLQSetup = 1;
LLQRefresh = 2;
LLQEvent = 3;
}
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.LLQErrorCode" -Type "UInt16" -Members @{
NoError = 0;
ServFull = 1;
Static = 2;
FormatErr = 3;
NoSuchLLQ = 4;
BadVers = 5;
UnknownErr = 6;
}
#
# NSEC3 (NextSECure3): Parameters
#
# DNSSEC NSEC3 Flags
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.NSEC3Flags" -Type "Byte" -Members @{
OptOut = 1; # [RFC5155]
}
# DNSSEC NSEC3 Hash Algorithms
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.NSEC3HashAlgorithm" -Type "Byte" -Members @{
SHA1 = 1; # [RFC5155]
}
#
# TKEY: Mode
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.TKEYMode" -Type "UInt16" -Members @{
ServerAssignment = 1; # Server assignment [RFC2930]
DH = 2; # Diffie-Hellman Exchange [RFC2930]
GSSAPI = 3; # GSS-API negotiation [RFC2930]
ResolverAssignment = 4; # Resolver assignment [RFC2930]
KeyDeletion = 5; # Key deletion [RFC2930]
}
#
# WINS
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.WINSMappingFlag" -Type "UInt32" -Members @{
Replication = 0;
NoReplication = 65536;
}
##############################################################################################################################################################
# WMI - GENERIC #
##############################################################################################################################################################
#
# Registry
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.RegistryHive" -Type "UInt32" -Members @{
HKCR = 2147483628; # HKEY_CLASSES_ROOT
HKCU = 2147483649; # HKEY_CURRENT_USER
HKLM = 2147483650; # HKEY_LOCAL_MACHINE
HKU = 2147483651; # HKEY_USERS
HKCC = 2147483653; # HKEY_CURRENT_CONFIG
}
##############################################################################################################################################################
# WMI - DNS RECORD #
##############################################################################################################################################################
#
# RecordType
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.WmiRecordType" -Type "UInt16" -Members @{
MicrosoftDNS_AType = 1; # Represents an Address (A) RR
MicrosoftDNS_NSType = 2; # Represents a Name Server (NS) RR
MicrosoftDNS_MDType = 3; # Represents a Mail Agent for Domain (MD) RR
MicrosoftDNS_MFType = 4; # Represents a Mail Forwarding Agent for Domain (MF) RR
MicrosoftDNS_CNAMEType = 5; # Represents a Canonical Name (CNAME) RR
MicrosoftDNS_SOAType = 6; # Represents a Start Of Authority (SOA) RR
MicrosoftDNS_MBType = 7; # Represents a Mailbox (MB) RR
MicrosoftDNS_MGType = 8; # Represents an MG RR
MicrosoftDNS_MRType = 9; # Represents a Mailbox Rename (MR) RR
MicrosoftDNS_WKSType = 11; # Represents a Well-Known Service (WKS) RR
MicrosoftDNS_PTRType = 12; # Represents a Pointer (PTR) RR
MicrosoftDNS_HINFOType = 13; # Represents a Host Information (HINFO) RR
MicrosoftDNS_MINFOType = 14; # Represents an Mail Information (MINFO) RR
MicrosoftDNS_MXType = 15; # Represents a Mail Exchanger (MX) RR
MicrosoftDNS_TXTType = 16; # Represents a Text (TXT) RR
MicrosoftDNS_RPType = 17; # Represents a Responsible Person (RP) RR
MicrosoftDNS_AFSDBType = 18; # Represents an Andrew File System Database Server (AFSDB) RR
MicrosoftDNS_X25Type = 19; # Represents an X.25 (X25) RR
MicrosoftDNS_ISDNType = 20; # Represents an ISDN RR
MicrosoftDNS_RTType = 21; # Represents a Route Through (RT) RR
MicrosoftDNS_SIGType = 24; # Represents a Signature (SIG) RR
MicrosoftDNS_KEYType = 25; # Represents a KEY RR
MicrosoftDNS_AAAAType = 28; # Represents an IPv6 Address (AAAA); often pronounced quad-A RR
MicrosoftDNS_NXTType = 30; # Represents a Next (NXT) RR
MicrosoftDNS_SRVType = 33; # Represents a Service (SRV) RR
MicrosoftDNS_ATMAType = 34; # Represents an ATM Address-to-Name (ATMA) RR.
MicrosoftDNS_WINSType = 65281; # Represents a WINS RR
MicrosoftDNS_WINSRType = 65282; # Represents a WINS-Reverse (WINSR) RR
}
##############################################################################################################################################################
# WMI - DNS ZONE #
##############################################################################################################################################################
#
# ZoneType - Used by WMI MicrosoftDNS_Zone and AD dnsProperty
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.ZoneType" -Type "UInt32" -Members @{
Hint = 0;
Master = 1;
Slave = 2;
Stub = 3;
Forwarder = 4;
}
#
# Dynamic update flag
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.DynamicUpdate" -Type "UInt32" -Members @{
None = 0;
All = 1;
SecureOnly = 2;
}
#
# Zone transfer flag
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.ZoneTransfer" -Type "UInt32" -Members @{
Any = 0;
NS = 1;
List = 2;
None = 3;
}
#
# Notify flag
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.Notify" -Type "UInt32" -Members @{
None = 0;
NS = 1;
List = 2;
}
##############################################################################################################################################################
# WMI - DNS SERVER #
##############################################################################################################################################################
#
# Auto-configure zones
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.AutoConfigZones" -Type "UInt32" -Members @{
None = 0; # None
AllowDynamicUpdateOnly = 1; # Only servers that allow dynamic updates
AllowNoDynamicUpdateOnly = 2; # Only servers that do not allow dynamic updates
All = 4; # All Servers
}
#
# Auto-creation / auto-update flag
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.ServerDynamicUpdate" -Type "UInt32" -SetFlagsAttribute -Members @{
NoRestriction = 0; # No Restrictions
NoSOAUpdate = 1; # Does not allow dynamic updates of SOA records
NoRootNSUpdate = 2; # Does not allow dynamic updates of NS records at the zone root
NoNSUpdate = 4; # Does not allow dynamic updates of NS records not at the zone root (delegation NS records)
}
#
# Boot method
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.BootMethod" -Type "UInt32" -Members @{
Unitialised = 0; # Uninitialized
FromFile = 1; # Boot from file
FromRegistry = 2; # Boot from registry
FromDirectoryAndRegistry = 3; # Boot from directory and registry
}
#
# DNSSEC
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.DnsSecMode" -Type "UInt32" -Members @{
None = 0; # No DNSSEC records are included in the response unless the query requested a resource record set of the DNSSEC record type.
All = 1; # DNSSEC records are included in the response according to RFC 2535.
Opt = 2; # DNSSEC records are included in a response only if the original client query contained the OPT resource record according to RFC 2671
}
#
# Logging
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.EventLogLevel" -Type "UInt32" -Members @{
None = 0; # None
Errors = 1; # Log only errors
ErrorsAndWarnings = 2; # Log only warnings and errors.
All = 4; # Log all events.
}
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.LogLevel" -Type "UInt32" -SetFlagsAttribute -Members @{
None = 0;
Query = 1;
Notify = 16;
Update = 32;
NonQuery = 254;
Questions = 256;
Answers = 512;
Send = 4096;
Receive = 8192;
Udp = 16384;
Tcp = 32768;
AllPackets = 65535;
DSWrite = 65536;
DSUpdate = 131072;
FullPackets = 16777216;
WriteThrough = 2147483648;
}
#
# Name validity checking
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.NameCheckFlag" -Type "UInt32" -Members @{
StrictRFCANSI = 0;
NonRFCANSI = 1;
MultibyteUTF8 = 2;
AllNames = 3;
}
#
# RPC mode
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.RpcProtocol" -Type "UInt32" -SetFlagsAttribute -Members @{
None = 0;
Tcp = 1;
NamedPipes = 2;
Lpc = 4;
}
##############################################################################################################################################################
# AD #
##############################################################################################################################################################
#
# DCPromo flag
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.DcPromoFlag" -Type "UInt32" -Members @{
None = 0; # No change to existing zone storage.
ConvertDomain = 1; # Zone is to be stored in DNS domain partition. See DNS_ZONE_CREATE_FOR_DCPROMO (section 2.2.5.2.7.1).
ConvertForest = 2; # Zone is to be stored in DNS forest partition. See DNS_ZONE_CREATE_FOR_DCPROMO_FOREST (section 2.2.5.2.7.1).
}
#
# Rank
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.Rank" -Type "Byte" -Members @{
None = 0; # Tombstoned record
CacheBit = 1; # The record came from the cache.
RootHint = 8; # The record is a preconfigured root hint.
OutsideGlue = 32; # This value is not used.
CacheNAAdditional = 49; # The record was cached from the additional section of a nonauthoritative response.
CacheNAAuthority = 65; # The record was cached from the authority section of a nonauthoritative response.
CacheAAdditional = 81; # The record was cached from the additional section of an authoritative response.
CacheNAAnswer = 97; # The record was cached from the answer section of a nonauthoritative response.
CacheAAuthority = 113; # The record was cached from the authority section of an authoritative response.
Glue = 128; # The record is a glue record in an authoritative zone.
NSGlue = 130; # The record is a delegation (type NS) record in an authoritative zone.
CacheAAnswer = 193; # The record was cached from the answer section of an authoritative response.
ZoneRecord = 240; # The record comes from an authoritative zone.
}
#
# Zone property fields
#
New-Enum -ModuleBuilder $IndentedDnsMB -Name "Indented.Dns.ZonePropertyID" -Type "UInt32" -Members @{
Type = 1; # The zone type. See dwZoneType (section 2.2.5.2.4.1).
AllowUpdate = 2; # Whether dynamic updates are allowed. See fAllowUpdate (section 2.2.5.2.4.1).
Securetime = 8; # The time; in seconds and expressed as an unsigned 64-bit integer; at which the zone became secure.
NoRefreshInterval = 16; # The zone no refresh interval. See dwNoRefreshInterval (section 2.2.5.2.4.1).
ScavengingServers = 17; # Servers that will perform scavenging. See aipScavengingServers (section 2.2.5.2.4.1).
AgingEnabledTime = 18; # The time interval before the next scavenging cycle. See dwAvailForScavengeTime (section 2.2.5.2.4.1).
RefreshInterval = 32; # The zone refresh interval. See dwRefreshInterval (section 2.2.5.2.4.1).
AgingState = 64; # Whether aging is enabled. See fAging (section 2.2.5.2.4.1).
DeletedFromHostname = 128; # The name of the server that deleted the zone. The value is a null-terminated Unicode string.
MasterServers = 129; # Servers to perform zone transfers. See aipMasters (section 2.2.5.2.4.1).
AutoNSServers = 130; # A list of servers which MAY autocreate a delegation. The list is formatted as DNS_ADDR_ARRAY (section 2.2.3.2.3).
DCPromoConvert = 131; # The flag value representing the state of conversion of the zone. See DcPromo Flag (section 2.3.1.1.2).
ScavengingServersDA = 144; # Servers that will perform scavenging. Same format as DSPROPERTY_ZONE_SCAVENGING_SERVERS.
MasterServersDA = 145; # Servers to perform zone transfers. Same format as DSPROPERTY_ZONE_MASTER_SERVERS.
AutoNSServersDA = 146; # A list of servers which MAY autocreate a delegation. Same format as DSPROPERTY_ZONE_AUTO_NS_SERVERS.
NodeDBFlags = 256; # See DNS_RPC_NODE_FLAGS (section 2.2.2.1.2).
}
function ReadADDnsDomainName {
# .SYNOPSIS
# Reads a domain-name from dnsRecord.
# .DESCRIPTION
# Internal use only.
#
# Domain name values are held in the following format:
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | LENGTH | NUMBER OF LABELS |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | LABEL LENGTH | |
# |--+--+--+--+--+--+--+--+ |
# / DATA /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# System.String
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader
)
$Length = $BinaryReader.ReadByte()
$NumberOfLabels = $BinaryReader.ReadByte()
$DomainName = @()
for ($i = 0; $i -lt $NumberOfLabels; $i++) {
$LabelLength = $BinaryReader.ReadByte()
$DomainName += New-Object String (, $BinaryReader.ReadChars($LabelLength))
}
# Drop the terminating byte
$BinaryReader.ReadByte() | Out-Null
return ([String]::Join('.', $DomainName) + '.')
}
function ReadADDnsCharacterString {
# .SYNOPSIS
# Reads a character-string from a DNS message.
# .DESCRIPTION
# Internal use only.
#
# Character string values are held in the following format:
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | LENGTH | |
# |--+--+--+--+--+--+--+--+ |
# / DATA /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# System.String
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader
)
$Length = $BinaryReader.ReadByte()
$CharacterString = New-Object String (, $BinaryReader.ReadChars($Length))
return $CharacterString
}
function ReadADDnsResourceRecord {
# .SYNOPSIS
# Reads common DNS resource record fields from a byte array.
# .DESCRIPTION
# Internal use only.
#
# Reads a byte array in the following format:
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | RDATA LENGTH |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | TYPE |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | VERSION | RANK |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | FLAGS |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | UPDATEDATSERIAL |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | TTL |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | RESERVED |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | TIMESTAMP |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
# / RDATA /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER SearchResultEntry
# A SearchResultEntry passed from Get-ADDnsRecord.
# .INPUTS
# System.IO.BinaryReader
# System.DirectoryServices.Protocols.SearchResultEntry
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[DirectoryServices.Protocols.SearchResultEntry]$SearchResultEntry
)
$ResourceRecord = New-Object PsObject -Property ([Ordered]@{
Name = ($SearchResultEntry.Attributes['name'].Item(0));
TTL = [UInt32]0;
RecordClass = [Indented.Dns.RecordClass]::IN;
RecordType = [Indented.Dns.RecordType]::Empty;
RecordDataLength = 0;
RecordData = "";
DN = $SearchResultEntry.DistinguishedName;
ZoneName = "";
objectGUID = ([GUID]$SearchResultEntry.Attributes['objectguid'].Item(0));
Rank = $null;
TimeStamp = $null;
UpdatedAtSerial = $null;
WhenCreated = ([DateTime]::ParseExact(($SearchResultEntry.Attributes['whencreated'].Item(0)), "yyyyMMddHHmmss.0Z", [Globalization.CultureInfo]::CurrentCulture));
DnsTombstone = $false;
})
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord")
# Property: ZoneName
$ResourceRecord.ZoneName = $ResourceRecord.DN -replace '^DC=[^,]+,DC=|,.+$'
# Property: Name - rebuild the name; concatenate with the zone name
if ($ResourceRecord.Name -eq '@') {
$ResourceRecord.Name = "$($ResourceRecord.ZoneName)."
}
else {
$ResourceRecord.Name = [String]::Format("{0}.{1}.",
$ResourceRecord.Name,
$ResourceRecord.ZoneName)
}
# Property: RecordDataLength
$ResourceRecord.RecordDataLength = $BinaryReader.ReadUInt16()
# Property: RecordType
$ResourceRecord.RecordType = [Indented.Dns.RecordType]($BinaryReader.ReadUInt16())
# Property: Version
$BinaryReader.ReadByte() | Out-Null
# Property: Rank
$ResourceRecord.Rank = [Indented.Dns.Rank]$BinaryReader.ReadByte()
# Property: Flags
$BinaryReader.ReadUInt16() | Out-Null
# Property: UpdatedAtSerial
$ResourceRecord.UpdatedAtSerial = $BinaryReader.ReadUInt32()
# Property: TTL
$ResourceRecord.TTL = $BinaryReader.ReadBEUInt32()
# Property: Reserved
$BinaryReader.ReadUInt32() | Out-Null
# Property: TimeStamp
$TimeStamp = $BinaryReader.ReadUInt32()
if ($TimeStamp -gt 0) {
$ResourceRecord.TimeStamp = (Get-Date '01/01/1601').AddHours($TimeStamp)
}
# Property: DnsTombstone
if ($SearchResultEntry.Attributes['dnstombstoned']) {
[Boolean]$ResourceRecord.DnsTombstone = $SearchResultEntry.Attributes['dnstombstoned'].Item(0)
}
# Method: ToString
$ResourceRecord | Add-Member ToString -MemberType ScriptMethod -Force -Value {
return [String]::Format("{0} {1} {2} {3} {4}",
$this.Name.PadRight(19, ' '),
$this.TTL.ToString().PadRight(5, ' '),
$this.RecordClass.ToString().PadRight(5, ' '),
$this.RecordType.ToString().PadRight(5, ' '),
$this.RecordData)
}
# Mark the beginning of the RecordData
$BinaryReader.SetPositionMarker()
$Params = @{BinaryReader = $BinaryReader; ResourceRecord = $ResourceRecord }
# Create appropriate properties for each record type
switch ($ResourceRecord.RecordType) {
([Indented.Dns.RecordType]::A) { $ResourceRecord = ReadADDnsARecord @Params; break }
([Indented.Dns.RecordType]::NS) { $ResourceRecord = ReadADDnsNSRecord @Params; break }
([Indented.Dns.RecordType]::MD) { $ResourceRecord = ReadADDnsMDRecord @Params; break }
([Indented.Dns.RecordType]::MF) { $ResourceRecord = ReadADDnsMFRecord @Params; break }
([Indented.Dns.RecordType]::CNAME) { $ResourceRecord = ReadADDnsCNAMERecord @Params; break }
([Indented.Dns.RecordType]::SOA) { $ResourceRecord = ReadADDnsSOARecord @Params; break }
([Indented.Dns.RecordType]::MB) { $ResourceRecord = ReadADDnsMBRecord @Params; break }
([Indented.Dns.RecordType]::MG) { $ResourceRecord = ReadADDnsMGRecord @Params; break }
([Indented.Dns.RecordType]::MR) { $ResourceRecord = ReadADDnsMRRecord @Params; break }
([Indented.Dns.RecordType]::WKS) { $ResourceRecord = ReadADDnsWKSRecord @Params; break }
([Indented.Dns.RecordType]::PTR) { $ResourceRecord = ReadADDnsPTRRecord @Params; break }
([Indented.Dns.RecordType]::HINFO) { $ResourceRecord = ReadADDnsHINFORecord @Params; break }
([Indented.Dns.RecordType]::MINFO) { $ResourceRecord = ReadADDnsMINFORecord @Params; break }
([Indented.Dns.RecordType]::MX) { $ResourceRecord = ReadADDnsMXRecord @Params; break }
([Indented.Dns.RecordType]::TXT) { $ResourceRecord = ReadADDnsTXTRecord @Params; break }
([Indented.Dns.RecordType]::RP) { $ResourceRecord = ReadADDnsRPRecord @Params; break }
([Indented.Dns.RecordType]::AFSDB) { $ResourceRecord = ReadADDnsAFSDBRecord @Params; break }
([Indented.Dns.RecordType]::X25) { $ResourceRecord = ReadADDnsX25Record @Params; break }
([Indented.Dns.RecordType]::ISDN) { $ResourceRecord = ReadADDnsISDNRecord @Params; break }
([Indented.Dns.RecordType]::RT) { $ResourceRecord = ReadADDnsRTRecord @Params; break }
([Indented.Dns.RecordType]::SIG) { $ResourceRecord = ReadADDnsSIGRecord @Params; break }
([Indented.Dns.RecordType]::KEY) { $ResourceRecord = ReadADDnsKEYRecord @Params; break }
([Indented.Dns.RecordType]::AAAA) { $ResourceRecord = ReadADDnsAAAARecord @Params; break }
([Indented.Dns.RecordType]::NXT) { $ResourceRecord = ReadADDnsNXTRecord @Params; break }
([Indented.Dns.RecordType]::SRV) { $ResourceRecord = ReadADDnsSRVRecord @Params; break }
([Indented.Dns.RecordType]::ATMA) { $ResourceRecord = ReadADDnsATMARecord @Params; break }
([Indented.Dns.RecordType]::WINS) { $ResourceRecord = ReadADDnsWINSRecord @Params; break }
([Indented.Dns.RecordType]::WINSR) { $ResourceRecord = ReadADDnsWINSRRecord @Params; break }
default { ReadADDnsUnknownRecord @Params }
}
return $ResourceRecord
}
function ReadADDnsUnknownRecord {
# .SYNOPSIS
# Reads properties for an unknown record type from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / <anything> /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
# Indented.Dns.AD.ResourceRecord
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.Unknown
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
# Create the basic Resource Record
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.Unknown")
# Property: BinaryData
$ResourceRecord | Add-Member BinaryData -MemberType NoteProperty -Value ($BinaryReader.ReadBytes($ResourceRecord.RecordDataLength))
return $ResourceRecord
}
function ReadADDnsARecord {
# .SYNOPSIS
# Reads properties for an A record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | ADDRESS |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.A
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.A")
# Property: IPAddress
$ResourceRecord | Add-Member IPAddress -MemberType NoteProperty -Value $BinaryReader.ReadIPv4Address()
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.IPAddress.ToString()
}
return $ResourceRecord
}
function ReadADDnsNSRecord {
# .SYNOPSIS
# Reads properties for an NS record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / NSDNAME /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.NS
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.NS")
# Property: Hostname
$ResourceRecord | Add-Member Hostname -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.Hostname
}
return $ResourceRecord
}
function ReadADDnsMDRecord {
# .SYNOPSIS
# Reads properties for an MD record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# Present for legacy support; the MD record is marked as obsolete in favour of MX.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / MADNAME /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.MD
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.MD")
# Property: Hostname
$ResourceRecord | Add-Member Hostname -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.Hostname
}
return $ResourceRecord
}
function ReadADDnsMFRecord {
# .SYNOPSIS
# Reads properties for an MF record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# Present for legacy support; the MF record is marked as obsolete in favour of MX.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / MADNAME /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.MF
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.MF")
# Property: Hostname
$ResourceRecord | Add-Member Hostname -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.Hostname
}
return $ResourceRecord
}
function ReadADDnsCNAMERecord {
# .SYNOPSIS
# Reads properties for an CNAME record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / CNAME /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.CNAME
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.CNAME")
# Property: Hostname
$ResourceRecord | Add-Member Hostname -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.Hostname
}
return $ResourceRecord
}
function ReadADDnsSOARecord {
# .SYNOPSIS
# Reads properties for an SOA record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | SERIAL |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | REFRESH |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | RETRY |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | EXPIRE |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | MINIMUM TTL |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / DATA /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / RESPONSIBLE PERSON /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.SOA
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.SOA")
# Property: Serial
$ResourceRecord | Add-Member Serial -MemberType NoteProperty -Value $BinaryReader.ReadBEUInt32()
# Property: Refresh
$ResourceRecord | Add-Member Refresh -MemberType NoteProperty -Value $BinaryReader.ReadBEUInt32()
# Property: Retry
$ResourceRecord | Add-Member Retry -MemberType NoteProperty -Value $BinaryReader.ReadBEUInt32()
# Property: Expire
$ResourceRecord | Add-Member Expire -MemberType NoteProperty -Value $BinaryReader.ReadBEUInt32()
# Property: MinimumTTL
$ResourceRecord | Add-Member MinimumTTL -MemberType NoteProperty -Value $BinaryReader.ReadBEUInt32()
# Property: NameServer
$ResourceRecord | Add-Member NameServer -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: ResponsiblePerson
$ResourceRecord | Add-Member ResponsiblePerson -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("{0} {1} (`n" +
" {2} ; serial`n" +
" {3} ; refresh ({4})`n" +
" {5} ; retry ({6})`n" +
" {7} ; expire ({8})`n" +
" {9} ; minimum ttl ({10})`n" +
")",
$this.NameServer,
$this.ResponsiblePerson,
$this.Serial.ToString().PadRight(10, ' '),
$this.Refresh.ToString().PadRight(10, ' '),
(ConvertTo-TimeSpanString -Seconds $this.Refresh),
$this.Retry.ToString().PadRight(10, ' '),
(ConvertTo-TimeSpanString -Seconds $this.Retry),
$this.Expire.ToString().PadRight(10, ' '),
(ConvertTo-TimeSpanString -Seconds $this.Expire),
$this.MinimumTTL.ToString().PadRight(10, ' '),
(ConvertTo-TimeSpanString -Seconds $this.Refresh))
}
return $ResourceRecord
}
function ReadADDnsMBRecord {
# .SYNOPSIS
# Reads properties for an MB record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# The MB record is marked as experimental.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / MADNAME /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.MB
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.MB")
# Property: Hostname
$ResourceRecord | Add-Member Hostname -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.Hostname
}
return $ResourceRecord
}
function ReadADDnsMGRecord {
# .SYNOPSIS
# Reads properties for an MG record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# The MG record is marked as experimental.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / MGMNAME /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.MG
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.MG")
# Property: MailboxName
$ResourceRecord | Add-Member Mailbox -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.MailboxName
}
return $ResourceRecord
}
function ReadADDnsMRRecord {
# .SYNOPSIS
# Reads properties for an MR record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# The MR record is marked as experimental.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / NEWNAME /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.MR
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.MR")
# Property: MailboxName
$ResourceRecord | Add-Member MailboxName -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.MailboxName
}
return $ResourceRecord
}
function ReadADDnsWKSRecord {
# TO-DO
#
# .SYNOPSIS
# Reads properties for an WKS record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | ADDRESS |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | PROTOCOL | /
# +--+--+--+--+--+--+--+--+ /
# / /
# / <BIT MAP> /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.WKS
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.WKS")
# Property: IPAddress
$ResourceRecord | Add-Member IPAddress -MemberType NoteProperty -Value $BinaryReader.ReadIPv4Address()
# Property: IPProtocolNumber
$ResourceRecord | Add-Member IPProtocolNumber -MemberType NoteProperty -Value $BinaryReader.ReadByte()
# Property: IPProtocolType
$ResourceRecord | Add-Member IPProtocolType -MemberType ScriptProperty -Value {
[Net.Sockets.ProtocolType]$this.IPProtocolNumber
}
# BitMap length in bytes, discounting the first five bytes (IPAddress and ProtocolType).
$Bytes = $BinaryReader.ReadBytes($ResourceRecord.RecordDataLength - 5)
$BinaryString = , $Bytes | ConvertTo-String -Binary
# Property: BitMap
$ResourceRecord | Add-Member BitMap -MemberType NoteProperty -Value $BinaryString
# Property: Ports (numeric)
$ResourceRecord | Add-Member Ports -MemberType ScriptProperty -Value {
$Length = $BinaryString.Length; $Ports = @()
for ([UInt16]$i = 0; $i -lt $Length; $i++) {
if ($BinaryString[$i] -eq 1) {
$Ports += $i
}
}
$Ports
}
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("{0} {1} ( {2} )",
$this.IPAddress,
$this.IPProtocolType,
"$($this.Ports)")
}
return $ResourceRecord
}
function ReadADDnsPTRRecord {
# .SYNOPSIS
# Reads properties for an PTR record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / PTRDNAME /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.PTR
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.PTR")
# Property: Hostname
$ResourceRecord | Add-Member Hostname -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.Hostname
}
return $ResourceRecord
}
function ReadADDnsHINFORecord {
# .SYNOPSIS
# Reads properties for an HINFO record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / CPU /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / OS /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.HINFO
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.HINFO")
# Property: CPU
$ResourceRecord | Add-Member CPU -MemberType NoteProperty -Value (ReadADDnsCharacterString $BinaryReader)
# Property: OS
$ResourceRecord | Add-Member OS -MemberType NoteProperty -Value (ReadADDnsCharacterString $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("""{0}"" ""{1}""",
$this.CPU,
$this.OS)
}
return $ResourceRecord
}
function ReadADDnsMINFORecord {
# .SYNOPSIS
# Reads properties for an MINFO record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / RMAILBX /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / EMAILBX /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.MINFO
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.MINFO")
# Property: ResponsibleMailbox
$ResourceRecord | Add-Member ResponsibleMailbox -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: ErrorMailbox
$ResourceRecord | Add-Member ErrorMailbox -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("{0} {1}",
$this.ResponsibleMailbox,
$this.ErrorMailbox)
}
return $ResourceRecord
}
function ReadADDnsMXRecord {
# .SYNOPSIS
# Reads properties for an MX record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | PREFERENCE |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / EXCHANGE /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.MX
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.MX")
# Property: Preference
$ResourceRecord | Add-Member Preference -MemberType NoteProperty -Value $BinaryReader.ReadUInt16()
# Property: Exchange
$ResourceRecord | Add-Member Exchange -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("{0} {1}",
$this.Preference.ToString().PadRight(5, ' '),
$this.Exchange)
}
return $ResourceRecord
}
function ReadADDnsTXTRecord {
# .SYNOPSIS
# Reads properties for an TXT record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / TXT-DATA /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.TXT
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.TXT")
# Property: Text
$ResourceRecord | Add-Member Text -MemberType NoteProperty -Value (ReadADDnsCharacterString $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.Text
}
return $ResourceRecord
}
function ReadADDnsRPRecord {
# .SYNOPSIS
# Reads properties for an RP record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / RMAILBX /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / EMAILBX /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.RP
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.RP")
# Property: ResponsibleMailbox
$ResourceRecord | Add-Member ResponsibleMailbox -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: TXTDomainName
$ResourceRecord | Add-Member TXTDomainName -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("{0} {1}",
$this.ResponsibleMailbox,
$this.TXTDomainName)
}
return $ResourceRecord
}
function ReadADDnsAFSDBRecord {
# .SYNOPSIS
# Reads properties for an AFSDB record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | SUBTYPE |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / HOSTNAME /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.AFSDB
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.AFSDB")
$SubType = $BinaryReader.ReadUInt16()
if ([Enum]::IsDefined([Idented.Dns.AFSDBSubType], $SubType)) {
$SubType = [Indented.Dns.AFSDBSubType]$SubType
}
# Property: SubType
$ResourceRecord | Add-Member SubType -MemberType NoteProperty -Value $SubType
# Property: Hostname
$ResourceRecord | Add-Member Hostname -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("{0} {1}",
$this.SubType,
$this.Hostname)
}
return $ResourceRecord
}
function ReadADDnsX25Record {
# .SYNOPSIS
# Reads properties for an X25 record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / PSDNADDRESS /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.X25
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.X25")
# Property: PSDNAddress
$ResourceRecord | Add-Member PSDNAddress -MemberType NoteProperty -Value (ReadADDnsCharacterString $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.PSDNAddress
}
return $ResourceRecord
}
function ReadADDnsISDNRecord {
# .SYNOPSIS
# Reads properties for an ISDN record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / ISDNADDRESS /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / SUBADDRESS /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.ISDN
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.ISDN")
# Property: ISDNAddress
$ResourceRecord | Add-Member ISDNAddress -MemberType NoteProperty -Value (ReadADDnsCharacterString $BinaryReader)
# Property: SubAddress
$ResourceRecord | Add-Member SubAddress -MemberType NoteProperty -Value (ReadADDnsCharacterString $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("""{0}"" ""{1}""",
$this.ISDNAddress,
$this.SubAddress)
}
return $ResourceRecord
}
function ReadADDnsRTRecord {
# .SYNOPSIS
# Reads properties for an RT record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | PREFERENCE |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / EXCHANGE /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.RT
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.RT")
# Property: Preference
$ResourceRecord | Add-Member Preference -MemberType NoteProperty -Value $BinaryReader.ReadUInt16()
# Property: IntermediateHost
$ResourceRecord | Add-Member IntermediateHost -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("{0} {1}",
$this.Preference.ToString().PadRight(5, ' '),
$this.IntermediateHost)
}
return $ResourceRecord
}
function ReadADDnsSIGRecord {
# TO-DO
#
# .SYNOPSIS
# Reads properties for an SIG record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | TYPE COVERED |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | ALGORITHM | LABELS |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | ORIGINAL TTL |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | SIGNATURE EXPIRATION |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | SIGNATURE INCEPTION |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | KEY TAG |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / SIGNER'S NAME /
# / /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / SIGNATURE /
# / /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.SIG
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.SIG")
# Property: TypeCovered
$ResourceRecord | Add-Member TypeCovered -MemberType NoteProperty -Value ([Indented.Dns.RecordType]$BinaryReader.ReadUIn16())
# Property: Algorithm
$ResourceRecord | Add-Member Algorithm -MemberType NoteProperty -Value ([Indented.Dns.EncryptionAlgorithm]$BinaryReader.ReadByte())
# Property: Labels
$ResourceRecord | Add-Member Labels -MemberType NoteProperty -Value $BinaryReader.ReadByte()
# Property: OriginalTTL
$ResourceRecord | Add-Member OriginalTTL -MemberType NoteProperty -Value $BinaryReader.ReadUInt32()
# Property: SignatureExpiration
$ResourceRecord | Add-Member SignatureExpiration -MemberType NoteProperty -Value ((Get-Date "01/01/1970").AddSeconds($BinaryReader.ReadUInt32()))
# Property: SignatureInception
$ResourceRecord | Add-Member SignatureInception -MemberType NoteProperty -Value ((Get-Date "01/01/1970").AddSeconds($BinaryReader.ReadUInt32()))
# Property: KeyTag
$ResourceRecord | Add-Member KeyTag -MemberType NoteProperty -Value $BinaryReader.ReadUInt16()
# Property: SignersName
$ResourceRecord | Add-Member SignersName -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: Signature
$Bytes = $BinaryReader.ReadBytes($ResourceRecord.RecordDataLength - $BinaryReader.BytesFromMarker)
$Base64String = , $Bytes | ConvertTo-String -Base64
$ResourceRecord | Add-Member Signature -MemberType NoteProperty -Value $Base64String
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("{0} {1} {2} ( ; type-cov={0}, alg={1}, labels={2}`n" +
" {3} ; Signature expiration`n" +
" {4} ; Signature inception`n" +
" {5} ; Key identifier`n" +
" {6} ; Signer`n" +
" {7} ; Signature`n" +
")",
$this.TypeCovered,
(([Byte]$this.Algorithm).ToString()),
([Byte]$this.Labels.ToString()),
$this.SignatureExpiration,
$this.SignatureInception,
$this.KeyTag,
$this.SignersName,
$this.Signature)
}
return $ResourceRecord
}
function ReadADDnsKEYRecord {
# TO-DO
#
# .SYNOPSIS
# Reads properties for an KEY record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | FLAGS |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | PROTOCOL | ALGORITHM |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / PUBLIC KEY /
# / /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# The flags field takes the following format, discussed in RFC 2535 3.1.2:
#
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
# | A/C | Z | XT| Z | Z | NAMTYP| Z | Z | Z | Z | SIG |
# +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.KEY
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.KEY")
# Property: Flags
$ResourceRecord | Add-Member Flags -MemberType NoteProperty -Value ($BinaryReader.ReadUInt16())
# Property: Authentication/Confidentiality (bit 0 and 1 of Flags)
$ResourceRecord | Add-Member AuthenticationConfidentiality -MemberType ScriptProperty -Value {
[Indented.Dns.KEYAC]([Byte]($this.Flags -shr 14))
}
# Property: Flags extension (bit 3)
if (($Flags -band 0x1000) -eq 0x1000) {
$ResourceRecord | Add-Member FlagsExtension -MemberType NoteProperty -Value $BinaryReader.ReadUInt16()
}
# Property: NameType (bit 6 and 7)
$ResourceRecord | Add-Member NameType -MemberType ScriptProperty -Value {
[Indented.Dns.KEYNameType]([Byte](($Flags -band 0x0300) -shr 9))
}
# Property: SignatoryField (bit 12 and 15)
$ResourceRecord | Add-Member SignatoryField -MemberType ScriptProperty -Value {
[Boolean]($this.Flags -band 0x000F)
}
# Property: Protocol
$ResourceRecord | Add-Member Protocol -MemberType NoteProperty -Value ([Indented.Dns.KEYProtocol]$BinaryReader.ReadByte())
# Property: Algorithm
$ResourceRecord | Add-Member Algorithm -MemberType NoteProperty -Value ([Indented.Dns.EncryptionAlgorithm]$BinaryReader.ReadByte())
if ($ResourceRecord.AuthenticationConfidentiality -ne [Indented.Dns.KEYAC]::NoKey) {
# Property: PublicKey
$Bytes = $BinaryReader.ReadBytes($ResourceRecord.RecordDataLength - $BinaryReader.BytesFromMarker)
$Base64String = , $Bytes | ConvertTo-String -Base64
$ResourceRecord | Add-Member PublicKey -MemberType NoteProperty -Value $Base64String
}
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("{0} {1} {2} ( {3} )",
$this.Flags,
([Byte]$this.Protocol).ToString(),
([Byte]$this.Algorithm).ToString(),
$this.PublicKey)
}
return $ResourceRecord
}
function ReadADDnsAAAARecord {
# .SYNOPSIS
# Reads properties for an AAAA record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | ADDRESS |
# | |
# | |
# | |
# | |
# | |
# | |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.AAAA
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.AAAA")
# Property: IPAddress
$ResourceRecord | Add-Member IPAddress -MemberType NoteProperty -Value $BinaryReader.ReadIPv6Address()
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.IPAddress.ToString()
}
return $Record
}
function ReadADDnsNXTRecord {
# TO-DO
#
# .SYNOPSIS
# Reads properties for an NXT record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / DOMAINNAME /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / <BIT MAP> /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.NXT
# .LINK
# http://www.ietf.org/rfc/rfc2535.txt
# http://www.ietf.org/rfc/rfc3755.txt
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.NXT")
# Property: DomainName
$ResourceRecord | Add-Member DomainName -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RRTypeBitMap
$Bytes = $BinaryReader.ReadBytes($ResourceRecord.RecordDataLength - $BinaryReader.BytesFromMarker)
$BinaryString = , $Bytes | ConvertTo-String -Binary
$ResourceRecord | Add-Member RRTypeBitMap -MemberType NoteProperty -Value $BinaryString
# Property: RRTypes
$ResourceRecord | Add-Member RRTypes -MemberType ScriptProperty -Value {
$RRTypes = @()
[Enum]::GetNames([Indented.Dns.RecordType]) |
Where-Object { [UInt16][Indented.Dns.RecordType]::$_ -lt $BinaryString.Length -and
$BinaryString[([UInt16][Indented.Dns.RecordType]::$_)] -eq '1' } |
ForEach-Object {
$RRTypes += [Indented.Dns.RecordType]::$_
}
$RRTypes
}
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("{0} {2}",
$this.DomainName,
"$($this.RRTypes)")
}
return $ResourceRecord
}
function ReadADDnsSRVRecord {
# .SYNOPSIS
# Reads properties for an SRV record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | PRIORITY |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | WEIGHT |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | PORT |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / TARGET /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.SRV
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.SRV")
# Property: Priority
$ResourceRecord | Add-Member Priority -MemberType NoteProperty -Value $BinaryReader.ReadBEUInt16()
# Property: Weight
$ResourceRecord | Add-Member Weight -MemberType NoteProperty -Value $BinaryReader.ReadBEUInt16()
# Property: Port
$ResourceRecord | Add-Member Port -MemberType NoteProperty -Value $BinaryReader.ReadBEUInt16()
# Property: Hostname
$ResourceRecord | Add-Member Hostname -MemberType NoteProperty -Value (ReadADDnsDomainName $BinaryReader)
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
[String]::Format("{0} {1} {2} {3}",
$this.Priority,
$this.Weight,
$this.Port,
$this.Hostname)
}
return $ResourceRecord
}
function ReadADDnsATMARecord {
# .SYNOPSIS
# Reads properties for an ATMA record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | FORMAT | |
# +--+--+--+--+--+--+--+--+ |
# / ATMADDRESS /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.ATMA
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.ATMA")
# Format
$Format = [Indented.Dns.ATMAFormat]$BinaryReader.ReadByte()
# ATMAAddress length, discounting the first byte (Format)
$Length = $RecorceRecord.RecordDataLength - 1
$ATMAAddress = New-Object Text.StringBuilder
switch ($Format) {
([Indented.Dns.ATMAFormat]::AESA) {
for ($i = 0; $i -lt $Length; $i++) {
$ATMAAddress.Append($BinaryReader.ReadChar()) | Out-Null
}
break
}
([Indented.Dns.ATMAFormat]::E164) {
for ($i = 0; $i -lt $Length; $i++) {
if ((3, 6) -contains $i) { $ATMAAddress.Append(".") | Out-Null }
$ATMAAddress.Append($BinaryReader.ReadChar()) | Out-Null
}
break
}
([Indented.Dns.ATMAFormat]::NSAP) {
for ($i = 0; $i -lt $Length; $i++) {
if ((1, 3, 13, 19) -contains $i) { $ATMAAddress.Append(".") | Out-Null }
$ATMAAddress.Append(('{0:X2}' -f $BinaryReader.ReadByte())) | Out-Null
}
break
}
}
# Property: Format
$ResourceRecord | Add-Member Format -MemberType NoteProperty -Value $Format
# Property: ATMAAddress
$ResourceRecord | Add-Member ATMAAddress -MemberType NoteProperty -Value $ATMAAddress.ToString()
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$this.ATMAAddress
}
return $ResourceRecord
}
function ReadADDnsDHCIDRecord {
# .SYNOPSIS
# Reads properties for an DHCID record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / <anything> /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.DHCID
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.DHCID")
# Property: BinaryData
$ResourceRecord | Add-Member BinaryData -MemberType NoteProperty -Value ($BinaryReader.ReadBytes($ResourceRecord.RecordDataLength))
return $ResourceRecord
}
function ReadADDnsWINSRecord {
# TO-DO
#
# .SYNOPSIS
# Reads properties for an WINS record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | LOCAL FLAG |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | LOOKUP TIMEOUT |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | CACHE TIMEOUT |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | NUMBER OF SERVERS |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / SERVER IP LIST /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.WINS
# .LINK
# http://msdn.microsoft.com/en-us/library/ms682748%28VS.85%29.aspx
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.WINS")
# Property: MappingFlag
$ResourceRecord | Add-Member MappingFlag -MemberType NoteProperty -Value ([Indented.Dns.WINSMappingFlag]$BinaryReader.ReadUInt32())
# Property: LookupTimeout
$ResourceRecord | Add-Member LookupTimeout -MemberType NoteProperty -Value $BinaryReader.ReadUInt32()
# Property: CacheTimeout
$ResourceRecord | Add-Member CacheTimeout -MemberType NoteProperty -Value $BinaryReader.ReadUInt32()
# Property: NumberOfServers
$ResourceRecord | Add-Member NumberOfServers -MemberType NoteProperty -Value $BinaryReader.ReadUInt32()
# Property: ServerList
$ResourceRecord | Add-Member ServerList -MemberType NoteProperty -Value @()
for ($i = 0; $i -lt $ResourceRecord.NumberOfServers; $i++) {
$ResourceRecord.ServerList += $BinaryReader.ReadIPv4Address()
}
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$Value = [String]::Format("L{0} C{1} ( {2} )",
$this.LookupTimeout,
$this.CacheTimeout,
"$($this.ServerList)")
if ($this.MappingFlag -eq [Indented.Dns.WINSMappingFlag]::NoReplication) {
$Value = "LOCAL $Value"
}
$Value
}
return $Record
}
function ReadADDnsWINSRRecord {
# TO-DO
#
# .SYNOPSIS
# Reads properties for an WINSR record from a byte array.
# .DESCRIPTION
# Internal use only.
#
# 1 1 1 1 1 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | LOCAL FLAG |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | LOOKUP TIMEOUT |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | CACHE TIMEOUT |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# | NUMBER OF SERVERS |
# | |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
# / DOMAIN NAME /
# / /
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#
# .PARAMETER BinaryReader
# A binary reader created by using New-BinaryReader (Indented.Common) containing a byte array representing the dnsRecord attribute.
# .PARAMETER ResourceRecord
# An Indented.Dns.AD.ResourceRecord object created by ReadADDnsResourceRecord.
# .INPUTS
# System.IO.BinaryReader
#
# The BinaryReader object must be created using New-BinaryReader (Indented.Common)
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord.WINSR
# .LINK
# http://msdn.microsoft.com/en-us/library/ms682748%28VS.85%29.aspx
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[IO.BinaryReader]$BinaryReader,
[Parameter(Mandatory = $true)]
[ValidateScript( { $_.PsObject.TypeNames -contains 'Indented.Dns.AD.ResourceRecord' } )]
$ResourceRecord
)
$ResourceRecord.PsObject.TypeNames.Add("Indented.Dns.AD.ResourceRecord.WINSR")
# Property: LocalFlag
$ResourceRecord | Add-Member LocalFlag -MemberType NoteProperty -Value ([Indented.Dns.WINSMappingFlag]$BinaryReader.ReadUInt32())
# Property: LookupTimeout
$ResourceRecord | Add-Member LookupTimeout -MemberType NoteProperty -Value $BinaryReader.ReadUInt32()
# Property: CacheTimeout
$ResourceRecord | Add-Member CacheTimeout -MemberType NoteProperty -Value $BinaryReader.ReadUInt32()
# Property: NumberOfDomains
$ResourceRecord | Add-Member NumberOfDomains -MemberType NoteProperty -Value $BinaryReader.ReadUInt32()
# Property: DomainNameList
$ResourceRecord | Add-Member DomainNameList -MemberType NoteProperty -Value @()
for ($i = 0; $i -lt $ResourceRecord.NumberOfDomains; $i++) {
$ResourceRecord.DomainNameList += ReadADDnsDomainName $BinaryReader
}
# Property: RecordData
$ResourceRecord | Add-Member RecordData -MemberType ScriptProperty -Force -Value {
$Value = [String]::Format("L{0} C{1} ( {2} )",
$this.LookupTimeout,
$this.CacheTimeout,
"$($this.DomainNameList)")
if ($this.LocalFlag -eq [Indented.Dns.WINSMappingFlag]::NoReplication) {
$Value = "LOCAL $Value"
}
$Value
}
return $Record
}
function Get-ADDnsPartition {
# .SYNOPSIS
# Get all partitions which are likely to contain DNS zones and records from Active Directory.
# .DESCRIPTION
# Get-ADDnsPartition executes a search against the configuration subtree to locate partitions which may hold DNS information.
# .PARAMETER Credential
# Specifies a user account that has permittion to perform this action. The default is the current user. Get-Credential can be used to create a PSCredential object for this parameter.
# .PARAMETER Server
# By default, Get-ADDnsPartition will use serverless binding to locate a suitable directory server. If the query must be targetted, or run against a non-local forest domain, a server must be specified.
# .INPUTS
# System.String
# .OUTPUTS
# Indented.Dns.AD.Partition
# .EXAMPLE
# Get-ADDnsPartition
# .EXAMPLE
# Get-ADDnsPartition -Credential (Get-Credential)
# .EXAMPLE
# Get-ADDnsPartition -Server "remoteserver.testdomain.com" -Credential (Get-Credential)
[CmdLetBinding()]
param(
[String]$Server = "",
[Parameter(ParameterSetName = "")]
[PSCredential]$Credential
)
$Params = @{}
if ($Credential) {
$Params.Add("Credential", $Credential)
}
$Params.Add("Server", "$Server")
# Find the configuration NC
$RootDSE = Get-LdapObject @Params -SearchScope Base
$ConfigurationNamingContext = $RootDSE.Attributes['configurationnamingcontext'].Item(0)
$LdapFilter = "(&(objectCategory=crossRef)(!name=Enterprise Configuration)(!name=Enterprise Schema))"
$Properties = "name", "whenCreated", "objectGUID", "msDS-NC-Replica-Locations", "nCName", "nETBIOSName"
Get-LdapObject @Params -SearchRoot $ConfigurationNamingContext -LdapFilter $LdapFilter -Properties $Properties | ForEach-Object {
$DN = [String]$_.Attributes['ncname'].Item(0)
if ($_.Attributes.AttributeNames -contains 'netbiosname') {
$DN = "CN=MicrosoftDNS,CN=System,$DN"
$PartitionType = "Legacy"
}
if ($DN -match '^dc=DomainDnsZones') {
$PartitionType = "Domain"
}
elseif ($DN -match '^dc=ForestDnsZones') {
$PartitionType = "Forest"
}
elseif (!$PartitionType) {
$PartitionType = "Custom"
}
$ReplicaLocations = @()
if ($_.Attributes.AttributeNames -contains 'msds-nc-replica-locations') {
$Count = $_.Attributes['msds-nc-replica-locations'].Count
for ($i = 0; $i -lt $Count; $i++) {
$ReplicaLocations += $_.Attributes['msds-nc-replica-locations'].Item($i) -replace '^[^,]+,CN=|,.+$'
}
}
$ADDnsPartition = New-Object PsObject -Property ([Ordered]@{
DN = $DN;
PartitionType = $PartitionType;
ReplicaLocations = $ReplicaLocations;
objectGUID = ([GUID]$_.Attributes['objectguid'].Item(0));
WhenCreated = ([DateTime]::ParseExact(($_.Attributes['whencreated'].Item(0)), "yyyyMMddHHmmss.0Z", [Globalization.CultureInfo]::CurrentCulture))
})
$ADDnsPartition.PsObject.TypeNames.Add("Indented.Dns.AD.Partition")
$ADDnsPartition
}
}
function Get-ADDnsRecord {
# .SYNOPSIS
# Get all DNS records from Active Directory.
# .DESCRIPTION
# Get-ADDnsRecord executes a search against a partition holding DNS data to locate dnsNode objects.
#
# Each dnsNode object contains one or more dnsRecord values.
#
# Get-ADDnsRecord can return records which have been deleteed, where DNS tombstoned is set to True. As record type identifiers are stripped from deleted records the record data is returned as a simple byte array (BinaryData).
# .PARAMETER ChaseLdapReferrals
# By default, Get-ADDnsRecord does not follow referrals returned by an LDAP query. RefErr messages may be returned when executing a search. This behaviour may be changed using this parameter. The search will be modified to follow all referrals.
# .PARAMETER Credential
# Specifies a user account that has permittion to perform this action. The default is the current user. Get-Credential can be used to create a PSCredential object for this parameter.
# .PARAMETER Name
# A name is used to define an LDAP filter for a specific record. The name value supports standard LDAP wildcard characters.
# .PARAMETER RecordType
# RecordType filtering is offered within this CmdLet as a convenience, it offers no operational benefit.
# .PARAMETER SearchRoot
# An LDAP distinguished named defining the starting point for this query.
# .PARAMETER Server
# By default, Get-ADDnsRecord will use serverless binding to locate a suitable directory server. If the query must be targetted, or run against a non-local forest domain, a server must be specified.
# .PARAMETER Tombstone
# Return dnsTombstoned records.
# .INPUTS
# System.String
# .OUTPUTS
# Indented.Dns.AD.ResourceRecord
#
# ResourceRecord may be considered to be a parent class, a record type specific class is returned.
# .EXAMPLE
# Get-ADDnsRecord
#
# All records under DomainDnsZones partition (the default search root) for the current domain.
# .EXAMPLE
# Get-ADDnsZone domain.example | Get-ADDnsRecord
#
# All records within the zone domain.example. The distinguishedName for the zone will be passed as the search root.
# .EXAMPLE
# Get-ADDnsRecord AComputer
#
# Get a record with a specific named.
# .EXAMPLE
# Get-ADDnsRecord -RecordType A
#
# Filter the records to A only.
# .EXAMPLE
# Get-ADDnsZone domain.example | Get-ADDnsRecord "@" SOA
#
# The SOA record for domain.example. @ represents the zone name and is used as a literal character in AD.
#
# The @ character is rewritten by Get-ADDnsRecord and is replaced with the zone name (parent container name in AD).
[CmdLetBinding(DefaultParameterSetName = 'ActiveRecords')]
param(
[Parameter(Position = 1, ParameterSetName = 'ActiveRecords')]
[String]$Name = "",
[Parameter(Position = 2, ParameterSetName = 'ActiveRecords')]
[Indented.Dns.RecordType[]]$RecordType,
[Parameter(Mandatory = $true, ParameterSetName = 'TombstonedRecords')]
[Switch]$Tombstone,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias("DN")]
[String]$SearchRoot = "DC=DomainDnsZones,DC=$($env:UserDnsDomain -replace '\.', ',DC=')",
[Switch]$ChaseLdapReferrals,
[String]$Server = "",
[PSCredential]$Credential
)
begin {
$Params = @{}
if ($Credential) {
$Params.Add("Credential", $Credential)
}
if ($ChaseLdapReferrals) {
$Params.Add("ReferralChasingOptions", [DirectoryServices.Protocols.ReferralChasingOptions]::All)
}
$Params.Add("Server", "$Server")
$LdapFilter = "(&(objectCategory=dnsNode)(!dnsTombStoned=TRUE))"
if ($Name) {
$LdapFilter = [String]::Format("(&(objectCategory=dnsNode)(name={0}))", $Name)
}
if ($Tombstone) {
$LdapFilter = "(&(objectCategory=dnsNode)(dnsTombStoned=TRUE))"
}
$Properties = "name", "distinguishedName", "whenCreated", "objectGuid", "dnsRecord", "dnsTombstoned"
}
process {
Get-LdapObject @Params -SearchRoot $SearchRoot -LdapFilter $LdapFilter -Properties $Properties | ForEach-Object {
$Count = $_.Attributes['dnsrecord'].Count
for ($i = 0; $i -lt $Count; $i++) {
$DnsRecord = $_.Attributes['dnsrecord'].GetValues([Byte[]])[$i]
$BinaryReader = New-BinaryReader -ByteArray $DnsRecord
$ResourceRecord = ReadADDnsResourceRecord -BinaryReader $BinaryReader -SearchResultEntry $_
# Filter the return values by record type (but only if a filter is defined)
if ($RecordType) {
if ($RecordType -contains $ResourceRecord.RecordType) {
$ResourceRecord
}
}
else {
$ResourceRecord
}
}
}
}
}
function Get-ADDnsZone {
# .SYNOPSIS
# Get all dnsZone objects from an Active Directory partition.
# .DESCRIPTION
# Get-ADDnsZone executes a search against a partition holding DNS information to locate dnsZone objects.
#
# Each dnsZone object contains a dnsProperty attribute. The dnsProperty attribute is a multi-value field describing several properties, each of which is decoded by this CmdLet.
# .PARAMETER ChaseLdapReferrals
# By default, Get-ADDnsZone does not follow referrals returned by an LDAP query. RefErr messages may be returned when executing a search. This behaviour may be changed using this parameter. The search will be modified to follow all referrals.
# .PARAMETER Credential
# Specifies a user account that has permittion to perform this action. The default is the current user. Get-Credential can be used to create a PSCredential object for this parameter.
# .PARAMETER Name
# A name is used to define an LDAP filter for a specific zone. The name value supports standard LDAP wildcard characters (* and ?).
# .PARAMETER SearchRoot
# An LDAP distinguished named defining the starting point for this query.
# .PARAMETER Server
# By default, Get-ADDnsZone will use serverless binding to locate a suitable directory server. If the query must be targetted, or run against a non-local forest domain, a server must be specified.
# .INPUTS
# System.String
# .OUTPUTS
# Indented.Dns.AD.Zone
# .EXAMPLE
# Get-ADDnsZone
#
# Get DNS zones from the DomainDnsZones partition in the current domain.
# .EXAMPLE
# Get-ADDnsPartition | Get-ADDnsZone
#
# Get DNS zones from all partitions in the current forest.
# .EXAMPLE
# Get-ADDnsPartition | Get-ADDnsZone indented.co.uk
#
# Get all instances of the indented.co.uk zone from all partitions in the forest.
# .EXAMPLE
# Get-ADDnsZone -Credential (Get-Credential)
# .EXAMPLE
# Get-ADDnsZone -Server "remoteserver.testdomain.com" -Credential (Get-Credential)
[CmdLetBinding()]
param(
[String]$Name = "",
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias("DN")]
[String]$SearchRoot = "DC=DomainDnsZones,DC=$($env:UserDnsDomain -replace '\.', ',DC=')",
[Switch]$ChaseLdapReferrals,
[String]$Server = "",
[Parameter(ParameterSetName = "")]
[PSCredential]$Credential
)
begin {
$Params = @{}
if ($Credential) {
$Params.Add("Credential", $Credential)
}
if ($ChaseLdapReferrals) {
$Params.Add("ReferralChasingOptions", [DirectoryServices.Protocols.ReferralChasingOptions]::All)
}
$Params.Add("Server", "$Server")
$LdapFilter = "(&(objectCategory=dnsZone))"
if ($Name) {
$LdapFilter = [String]::Format("(&(objectCategory=dnsZone)(name={0}))", $Name)
}
$Properties = "name", "distinguishedName", "whenCreated", "objectGuid", "dnsProperty"
}
process {
Get-LdapObject @Params -SearchRoot $SearchRoot -LdapFilter $LdapFilter -Properties $Properties | ForEach-Object {
$ADDnsZone = New-Object PsObject -Property ([Ordered]@{
ZoneName = ($_.Attributes['name'].Item(0));
DN = $_.DistinguishedName;
objectGUID = ([GUID]$_.Attributes['objectguid'].Item(0));
WhenCreated = ([DateTime]::ParseExact(($_.Attributes['whencreated'].Item(0)), "yyyyMMddHHmmss.0Z", [Globalization.CultureInfo]::CurrentCulture))
Aging = $false;
AgingEnabledDate = $Null;
AllowNSRecordsAutoCreation = [IPAddress[]]@();
DataFile = "";
DeletedFromHostname = "";
DynamicUpdate = [Indented.Dns.DynamicUpdate]"None";
ForwarderUseRecursion = $false;
MasterServers = [IPAddress[]]@();
NoRefreshInterval = $Null;
RefreshInterval = $Null;
ScavengeServers = [IPAddress[]]@();
SecureTime = $Null;
ZoneType = [Indented.Dns.ZoneType]::Primary;
})
$ADDnsZone.PsObject.TypeNames.Add("Indented.Dns.AD.Zone")
# Decode the dnsProperty field
$Count = $_.Attributes['dnsproperty'].Count
for ($i = 0; $i -lt $Count; $i++) {
$DnsProperty = $_.Attributes['dnsproperty'].GetValues([Byte[]])[$i]
$BinaryReader = New-BinaryReader -ByteArray $DnsProperty
$DataLength = $BinaryReader.ReadUInt32()
$NameLength = $BinaryReader.ReadUInt32()
$Flag = $BinaryReader.ReadUInt32()
$Version = $BinaryReader.ReadUInt32()
$ZonePropertyID = [Indented.Dns.ZonePropertyID]($BinaryReader.ReadUInt32())
switch ($ZonePropertyID) {
([Indented.Dns.ZonePropertyID]::AgingEnabledTime) {
$AgingEnabledHours = $BinaryReader.ReadUInt32()
if ($AgingEnabledHours -gt 0) {
# Property: AgingEnabledDate
$ADDnsZone.AgingEnabledDate = (Get-Date "01/01/1601").AddHours($AgingEnabledHours)
}
break
}
([Indented.Dns.ZonePropertyID]::AgingState) {
if ($BinaryReader.ReadUInt32() -eq 1) {
# Property: Aging
$ADDnsZone.Aging = $true
}
break
}
([Indented.Dns.ZonePropertyID]::AllowUpdate) {
# Property: DynamicUpdate
$ADDnsZone.DynamicUpdate = [Indented.Dns.DynamicUpdate]($BinaryReader.ReadByte())
break
}
([Indented.Dns.ZonePropertyID]::AutoNSServers) {
if ($DataLength -ge 4) {
$NumberOfServers = $BinaryReader.ReadUInt32()
for ($j = 0; $j -lt $NumberOfServers; $j++) {
# Property: AllowNSRecordsAutoCreation
$ADDnsZone.AllowNSRecordsAutoCreation += $BinaryReader.ReadIPv4Address()
}
}
break
}
([Indented.Dns.ZonePropertyID]::AutoNSServersDA) {
# Ignore this value
break
}
([Indented.Dns.ZonePropertyID]::DCPromoConvert) {
# Hide this property
break
}
([Indented.Dns.ZonePropertyID]::DeletedFromHostname) {
# Property: DeletedFromHostname
$ADDnsZone.DeletedFromHostname = ConvertTo-String ($BinaryReader.ReadBytes($DataLength)) -Unicode
break
}
([Indented.Dns.ZonePropertyID]::MasterServers) {
# Ignore this value
break
}
([Indented.Dns.ZonePropertyID]::MasterServersDA) {
$MaxCount = $BinaryReader.ReadUInt32()
$AddressCount = $BinaryReader.ReadUInt32()
# Drop padding / reserved bytes
$BinaryReader.ReadBytes(24) | Out-Null
for ($j = 0; $j -lt $AddressCount; $j++) {
# Each address is in a specific format across a number of fields
$AddressFamily = [Net.Sockets.AddressFamily]($BinaryReader.ReadUInt16())
# Probably need to reverse the endian order here if it's used.
$Port = $BinaryReader.ReadUInt16()
# The format includes sequential fields for both IPv4 and IPv6 addressing
$IPv4 = $BinaryReader.ReadIPv4Address()
$IPv6 = $BinaryReader.ReadIPv6Address()
if ($AddressFamily -eq [Net.Sockets.AddressFamily]::InterNetwork) {
# Property: MasterServers
$ADDnsZone.MasterServers += $IPv4
}
elseif ($AddressFamily -eq [Net.Sockets.AddressFamily]::InterNetworkV6) {
# Property: MasterServers
$ADDnsZone.MasterServers += $IPv6
}
# Read off and discard the trailing data
$BinaryReader.ReadBytes(8) | Out-Null
# The SALen field (dnscmd returns this, ignoring it here beyond this comment)
$BinaryReader.ReadUInt32() | Out-Null
# Read off and discard the trailing data
$BinaryReader.ReadBytes(28) | Out-Null
}
break
}
([Indented.Dns.ZonePropertyID]::NodeDBFlags) {
# Ignore this value
break
}
([Indented.Dns.ZonePropertyID]::NoRefreshInterval) {
# Property: NoRefreshInterval
$ADDnsZone.NoRefreshInterval = New-TimeSpan -Hours $BinaryReader.ReadUInt32()
break
}
([Indented.Dns.ZonePropertyID]::RefreshInterval) {
# Property: RefreshInterval
$ADDnsZone.RefreshInterval = New-TimeSpan -Hours $BinaryReader.ReadUInt32()
break
}
([Indented.Dns.ZonePropertyID]::ScavengingServers) {
if ($DataLength -ge 4) {
$NumberOfServers = $BinaryReader.ReadUInt32()
for ($j = 0; $j -lt $NumberOfServers; $j++) {
# Property: ScavengeServers
$ADDnsZone.ScavengeServers += $BinaryReader.ReadIPv4Address()
}
}
break
}
([Indented.Dns.ZonePropertyID]::ScavengingServersDA) {
# Ignore this value
break
}
([Indented.Dns.ZonePropertyID]::SecureTime) {
$SecureTimeSeconds = $BinaryReader.ReadUInt64()
if ($SecureTimeSeconds -gt 0) {
# Property: SecureTime
$ADDnsZone.SecureTime = (Get-Date "01/01/1601").AddSeconds($SecuretimeSeconds)
}
break
}
([Indented.Dns.ZonePropertyID]::Type) {
# Property: ZoneType
$ADDnsZone.ZoneType = [Indented.Dns.ZoneType]$BinaryReader.ReadUInt32()
break
}
}
}
$ADDnsZone
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment