Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure how to do this easily considering that the InputBox call is modal so you can't easily try to find the window handle and do a set-foreground on that window (unless you attempt to use a background job). Rather than use this VisualBasic text input box, how about a "roll your own" implementation using WPF/XAML. It is pretty easy but it does require WPF which is installed by PowerShell 2.0 if necessary.</p> <pre><code>$Xaml = @' &lt;Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="Window" Title="Name" Height="137" Width="444" MinHeight="137" MinWidth="100" FocusManager.FocusedElement="{Binding ElementName=TextBox}" ResizeMode="CanResizeWithGrip" &gt; &lt;DockPanel Margin="8"&gt; &lt;StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right"&gt; &lt;Button x:Name="OKButton" Width="60" IsDefault="True" Margin="12,12,0,0" TabIndex="1" &gt;_OK&lt;/Button&gt; &lt;Button Width="60" IsCancel="True" Margin="12,12,0,0" TabIndex="2" &gt;_Close&lt;/Button&gt; &lt;/StackPanel&gt; &lt;StackPanel &gt; &lt;Label x:Name="Label" Margin="-5,0,0,0" TabIndex="3"&gt;Label:&lt;/Label&gt; &lt;TextBox x:Name="TextBox" TabIndex="0" /&gt; &lt;/StackPanel&gt; &lt;/DockPanel&gt; &lt;/Window&gt; '@ if ([System.Threading.Thread]::CurrentThread.ApartmentState -ne 'STA') { throw "Script can only be run if PowerShell is started with -STA switch." } Add-Type -Assembly PresentationCore,PresentationFrameWork $xmlReader = [System.Xml.XmlReader]::Create([System.IO.StringReader] $Xaml) $form = [System.Windows.Markup.XamlReader]::Load($xmlReader) $xmlReader.Close() $window = $form.FindName("Window") $window.Title = "My App Name" $label = $form.FindName("Label") $label.Content = "What is your name?" $textbox = $form.FindName("TextBox") $okButton = $form.FindName("OKButton") $okButton.add_Click({$window.DialogResult = $true}) if ($form.ShowDialog()) { $textbox.Text } </code></pre> <p>This could be rather easily wrapped up into a Read-GuiText function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload