[Microsoft.VisualBasic.Interaction]::InputBox and Powershell 7.0


i’m new to Powershell 7.0 and trying to use some old code from “classic” Powershell.

Unfortunately, i’m in trouble with the section of inputbox command.

Here a part of my script :

add-type -assemblyName “Microsoft.VisualBasic”

add-type -AssemblyName System.Windows.Forms

$strNow = Get-Date -Format g

[String]$UserName = $env:USERNAME

[String]$ComputerName = $env:COMPUTERNAME

$ComputerName = [Microsoft.VisualBasic.Interaction]::InputBox("Number PC… ", “Message - $strNow - $UserName”, $ComputerName)

On powershell 5, no issue but with the 7.0, i got the error :

Method invocation failed because [Microsoft.Visualbasic.Interaction] does not contain a method named ‘InputBox’.

I don’t understand why and how fix that. Is someone could help me ?

thanks a lot !

i tried with adding :


but i got same error :frowning:


You’re running into API differences between .NET Framework which was used for Windows PowerShell (version 1-5.1), and .NET Core which is used in PowerShell Core (version 6+). This blog post describes the split: PowerShell Core vs. PowerShell: What are the differences?.

The VisualBasic Interaction features you’re trying to use aren’t implemented in .NET Core. See the following github issue reports: 12614 11513
Based on 12614, it looks like you can import the specific .dll that contains that method if you want to force it to work, but you probably won’t get all the functionality and it might be unreliable and it won’t be forward-compatible as Microsoft is ending development of .NET Framework in favor of .NET Core. A better solution is to write your GUI functions using Windows Forms, which are implemented in .NET Core.

thanks grokkit ! thanks a lot. the article is really interesting and i get a better view about powershell core and classic powershell ! now, i will have to learn how to make messagebox with input with windowsforms.

thank you for your answer !