I'm doing some tests with a domain that I have, I want that, when doing the TXT query, receive a string in base64 and decode it showing the message.
On Linux, it works perfectly:
$ dig -t txt my.domain.com +short | sed -e 's/^"//' -e 's/"$//' | base64 -d > file.txt
$ cat file.txttesting out my txt records
Now I want to do the same thing, except that in Windows, by default Windows does not have dig, but it has a command that is the following:
C:\Users\User\xyz>powershell Resolve-DnsName my.domain.com -Type
TXT > test
C:\Users\Avell\xyz>type test
Name Type TTL Section Strings
---- ---- --- ------- -------
my.domain.com TXT 10557 Answer
{dGVzdGluZyBvdXQgbXkgdHh0IHJlY29yZHMK}How could I adapt the command above (Linux) to work on Windows, taking only the stiring in base64 and decoding to show the message.
21 Answer
Or spend the needed time to learn PowerShell, by leveraging all the free resources and videos on Youtube to understand all the parts of PowerShell, and what can be done natively and when you need to code it yourself and when you need to pull in 3rdP tools.
This is not the first time this has been asked. A quick web search use 'PowerShell Sed' and 'PowerShell Grep', will show you a good list of these and even examples.
Get-Content Gets the content of the item at the specified location.
Select-String Finds text in strings and files.
sed in PowerShell
PowerShell – UNIX SED Equivalent – Change Text In File
Using sed and grep in PowerShell
Grep, the PowerShell way
How to “grep” in PowerShell
How To Grep in PowerShell
Quick Tip: PowerShell Grep Equivalent
POWERSHELL: SEARCH FOR STRING OR GREP FOR POWERSHELL
Secondly, Leverage the Microsoft powershellgallery directly in your PowerShell console or the new Windows Terminal ...
Find-Module -Name '*grep*' | Format-Table -AutoSize
Version Name Repository Description
------- ---- ---------- -----------
1.1.0 PoshGrep PSGallery Greplike PowerShell function Find-Package -Name '*grep*' | Format-Table -AutoSize
Name Version Source Summary
---- ------- ------ -------
wk.Grep 0.2.0 nuget.org Package Description
Liv.Grep 1.0.5436.17982 nuget.org Grep utility written in c#. Makes it easy to query command line outputs
AstroGrep 4.3.2 nuget.org This application and its source code are freely distributable.
GRepo 1.0.0 nuget.org GRepo
PoshGrep 1.1.0 PSGallery Greplike PowerShell function... or when using PowerShell editors - which provide popup help / IntelliSense (PowerShell_ISE built-in, VScode download, PowerShell Plus which are free) or (Sapien's PowerShell Studio - cost money.)
Lastly, you are using dig in your code as well. For that see this:
PowerShell: Query DNS Server for A, PTR, MX, NS and other records