Powershell...because fuck documenation.
$records=(get-dnsserverresourcerecord -zonename $zone -computername $dnsServer)
If you don't want records starting with a _, you not only need to regex by alphanumeric characters (\w)
https://devblogs.microsoft.com/scripting/powershell-regex-crash-course-part-2-of-5/ -- where they defined
\w | Matches an alphanumeric character |
No, not it doesn't. It matches any *word* character which in addition to alphanumeric characters includes underscore.
foreach ($record in $records) { if ($record.HostName -match '^\w' -and $record.Hostname -notmatch '^_') { $record } }
At any rate, the final working regex (once put in the script) to remove a lot of the housekeeping DNS records:
if ($name -notlike '*cgi.int*' -and $name -match '^[A-Za-z0-9]' -and $name -notlike '*_msdcs*')
Comments
Post a Comment