Powershell Encoded Command, sqlcmd, and csv Query Output

Use of bcp is blocked where I am working now. But Powershell and sqlcmd are very much available on the Windows workstations we use. Just as with bcp, smithing text for sqlcmd input can be a little tricky, same with Powershell. But Powershell has an EncodedCommand feature which allows you to feed input to it as a base 64 string. This will be a quick demo of the use of this feature and output of a faux comma delimited (csv) file with data.

Disclaimer: scripts that rely extensively on os.system()calls from Python are indeed hacky and mousetrappy. I think the saying goes "Necessity is a mother," or something similar. Onward.

Getting the base 64 string from the original string:

First our SQL code that queries a mock table I made in my mock database: