1

I wrote a batch script in which an InputBox is required, first of all this is the code line:

powershell -Command "& {Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox('Enter your command: [*here i want a line break*] Example commands: [*and here i want a line break*] example command', 'Input box example')}" > %TEMP%\out.tmp

How do I insert a line break there? Pls help me, searching for hours now.

Kind regards, jcjms

Compo
  • 36,585
  • 5
  • 27
  • 39
  • jcjms, I hace removed some of your tags. This question is relevant only to a small part of your [[tag:powershell]] code, and to designing the [[tag:inputbox]] with a particular layout. It has nothing whatsover to do with a [[tag:batch-file]], the [[tag:command-prompt]], or a [[tag:messagebox]]. Please be more considerate when assigning tags to your questions. – Compo Nov 27 '21 at 13:51

1 Answers1

3

You can do this like:

powershell -Command "& {Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox(\"Enter your command: `r`nExample commands: `r`nexample command\", 'Input box example')}"

or

powershell -Command "& {Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox('Enter your command: {0}Example commands: {0}example command' -f [environment]::Newline, 'Input box example')}"

enter image description here


As mklement0 commented.
There is no need to enclose the command in & {..}. You can simply put quotes around the command:

powershell -Command "Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox(\"Enter your command: `r`nExample commands: `r`nexample command\", 'Input box example')"

or

powershell -Command "Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox('Enter your command: {0}Example commands: {0}example command' -f [environment]::Newline, 'Input box example')"
Theo
  • 57,719
  • 8
  • 24
  • 41