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

Welcome Forums General PowerShell Q&A [Microsoft.VisualBasic.Interaction]::InputBox and Powershell 7.0

Viewing 3 reply threads
  • Author
    Posts
    • #252557
      Participant
      Topics: 1
      Replies: 2
      Points: 16
      Rank: Member

      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 !

    • #252569
      Participant
      Topics: 1
      Replies: 2
      Points: 16
      Rank: Member

      i tried with adding :

      [void][Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’)

      but i got same error 🙁

       

    • #252611
      Senior Moderator
      Topics: 10
      Replies: 168
      Points: 899
      Helping Hand
      Rank: Major Contributor

      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.

    • #252941
      Participant
      Topics: 1
      Replies: 2
      Points: 16
      Rank: Member

      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 !

Viewing 3 reply threads
  • You must be logged in to reply to this topic.