Skip to main content

An underscore is an alphanumeric character...

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 

\wMatches 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

Popular posts from this blog

One liner to temporarily monitor a web page

Just what the title says... while ($true) {if ((invoke-webrequest https://redacted.com -usebasicparsing).content | out-string | %{$_ -like '*Log in to your account*'}) {get-date; write-host "OK -- redacted.com contains logon string"} else {send-mailmessage -from redacted+221BBakerStreet@gmail.com -to redacted@gmail.com -subject "Check the AWS VPN" -smtpServer "smtp.charter.net" -port 587}; sleep 300}