Thanks again for sharing an interesting solution.
Little tip to take advantage of thinBASIC string specification over multiple lines.
Instead of this:
VBNETCode = "$vbnetCode = @" + CHR$(34) + vbCRLF
VBNETCode = VBNETCode + "Imports System" + vbCRLF
VBNETCode = VBNETCode + "Public Class HelloWorld" + vbCRLF
VBNETCode = VBNETCode + " Public Function GetMessage() As String" + vbCRLF
VBNETCode = VBNETCode + " Return " + chr$(34) + "Hello from VB.NET!" + chr$(34) + vbCRLF
VBNETCode = VBNETCode + " End Function" + vbCRLF
VBNETCode = VBNETCode + "End Class" + vbCRLF
VBNETCode = VBNETCode + Chr$(34) + "@" + vbCRLF
VBNETCode = VBNETCode + "Add-Type -TypeDefinition $vbnetCode -Language VisualBasic" + VBCRLF
VBNETCode = VBNETCode + "$helloWorld = New-Object HelloWorld" + VBCRLF
VBNETCode = VBNETCode + "$message = $helloWorld.GetMessage()" + VBCRLF
VBNETCode = VBNETCode + "Write-Output $message" + VBCRLF
...you can do this (difference is in adding + sign at the end of the line):
VBNETCode = "$vbnetCode = @" + CHR$(34) + vbCRLF +
"Imports System" + vbCRLF +
"Public Class HelloWorld" + vbCRLF +
" Public Function GetMessage() As String" + vbCRLF +
" Return " + chr$(34) + "Hello from VB.NET!" + chr$(34) + vbCRLF +
" End Function" + vbCRLF +
"End Class" + vbCRLF +
Chr$(34) + "@" + vbCRLF +
"Add-Type -TypeDefinition $vbnetCode -Language VisualBasic" + VBCRLF +
"$helloWorld = New-Object HelloWorld" + VBCRLF +
"$message = $helloWorld.GetMessage()" + VBCRLF +
"Write-Output $message" + VBCRLF
Petr