Skip to main content

Posts

Counting Ports for Port Exhaustion Troubleshooting

Get-NetTCPConnection | Group-Object -Property State, OwningProcess | Select -Property Count, Name, @{Name="ProcessName";Expression={(Get-Process -PID ($_.Name.Split(',')[-1].Trim(' '))).Name}}, Group | Sort Count -Descending
Recent posts

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  \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*')

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}