People keep saying how amazing ChatGPT is, so I thought I'd try it on a C# to PowerShell conversion.

What the heck even is this?

@jaykul it's broadly correct. Of course C# to PS isn't a very complex conversion, normally. Not sure where the bash box came from and a few parts look a little weird.

@jamie @otterkring in the end, I gave it a lot more context, and got a much better result, but...

It still used the PS1 syntax with the inline parameters and New-Object

It refuses to use the $sb.Append overloads the original code uses, doing string concatenation instead...

It didn't use `[void]` with $sb.Append (the way it DID in the screenshot), so it output the StringBuilder repeatedly. When I asked it to fix that, it mangled the code...

@jamie @otterkring for what it's worth, I did convert it into something that worked for me.

So I now have a function you can use in #PowerShell to syntax highlight arbitrary code roughly the way #PSReadLine does it:

https://github.com/Jaykul/EzTheme/commit/58c5883514f787e42e0cd4aaef864c299542cc2d

Add Show-Code · Jaykul/EzTheme@58c5883

An extensible module for PowerShell color themes. Contribute to Jaykul/EzTheme development by creating an account on GitHub.

GitHub