0

I am using Visual Studio to create a GUI environment for all my PowerShell scripts together to create a common platform . I have one problem with the text box . I want to have a text box so all the results appear there . Right now only the last command is appearing there .

Any suggestions ?

 <TextBox  x:Name="Information" HorizontalAlignment="Left" Margin="10,116,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Grid.ColumnSpan="3" Height="255" Width="678"/>

and I want at this texbox to appear the following messages

$WPFMapping.Add_Click({
    {
        $WPFInformation.Text = " We Will try to map the drives"}
    if (((New-Object System.IO.DriveInfo("N:")).DriveType -ne
    "NoRootDirectory"))
    {
        $WPFInformation.Text = " N drive is already mounted and accessible"}
    else {
        net use /persistent:yes N: "this drive"
        Write-Host     "mounting"}
    if (((New-Object System.IO.DriveInfo("V:")).DriveType -ne
    "NoRootDirectory"))
    {
        $WPFInformation.Text = " V drive is already mounted and accessible"}
    else  {
        $WPFInformation.Text = " V drive mapping in progress"}
    net use /persistent:yes V: "this drive"
    $WPFInformation.Text = " V drive mapping has been completed"
})
3
  • Any code you can share? Commented Dec 19, 2018 at 10:13
  • Without showing the relevant parts of your code, I doubt if anyone will be able to answer this.. Commented Dec 19, 2018 at 10:14
  • I will try to share a part of the code but I don't know if it will help Commented Dec 19, 2018 at 10:27

1 Answer 1

1

By setting the text in $WPFInformation.Text for the second drive mapping (V:), you overwrite the text you have set in there earlier for the N: mapping.

To append extra lines to the textbox, use

$WPFInformation.Text += [Environment]::NewLine
$WPFInformation.Text += " V drive is already mounted and accessible"

etc. for every next line you want to add.

You can also use AppendText() to add the new lines in there:

$WPFInformation.AppendText("`r`n V drive is already mounted and accessible")

Where `r`n represents the CRLF newline.

p.s. Of course, make sure the textbox's MultiLine property is set to $WPFInformation.Multiline = $true

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.