Many people may not want to create a COM dll using .NET Framework,
especially if it is just a small job, not worthy of being created as a COM dll.
In that case, using PSCom from thinBasic may be a better solution when VB.NET or C# code is needed.
Here's thinBasic code to create a VB.NET object, and call a VB.NET method from thinBasic.
uses "console"
dim ps as iDispatch
dim result as string
ps = CreateObject("PSCom.PSScript")
if IsComObject(ps) Then
result = ps.ExecuteScript("e:\utils\embedvbnet.ps1")
printl result
EndIf
ps = Nothing
Here's the PowerShell code (embedvbnet.ps1) to create the VB.NET object.
# Define the VB.NET code as a string
$vbnetCode = @"
Imports System
Public Class HelloWorld
Public Function GetMessage() As String
Return "Hello from VB.NET!"
End Function
End Class
"@
# Use Add-Type to compile the VB.NET code
Add-Type -TypeDefinition $vbnetCode -Language VisualBasic
# Create an instance of the VB.NET class
$helloWorld = New-Object HelloWorld
# Call the method and display the message
$message = $helloWorld.GetMessage()
Write-Output $message
Running the thinBasic code from the console results in Hello from VB.NET being displayed.
Joe