Welcome › Forums › General PowerShell Q&A › [Microsoft.VisualBasic.Interaction]::InputBox and Powershell 7.0
- This topic has 3 replies, 2 voices, and was last updated 5 months ago by
Participant.
-
AuthorPosts
-
-
August 26, 2020 at 8:54 am #252557
Hello,
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 !
-
August 26, 2020 at 9:11 am #252569
i tried with adding :
[void][Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’)
but i got same error 🙁
-
August 26, 2020 at 11:35 am #252611
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. -
August 27, 2020 at 5:07 am #252941
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 !
-
-
AuthorPosts
- The topic ‘[Microsoft.VisualBasic.Interaction]::InputBox and Powershell 7.0’ is closed to new replies.