I am fighting with outputting text file and getting file content in exactly the same way as it was provided by the user. I tried to find an answer but the only thing I can find is how to change multiline into one string which is quite the opposite I need.
How to ensure that input provided by the user in multiline will not be altered to single line in PowerShell?
Details:
In inputbox I provide details in multiline:

PowerShell saves the output in one line:

I want PowerShell to save multiline input and then show multiline output.
Here is the code:
function Notes
{
$var = $Users.Text
$var | Out-File C:\Users\A570654\Desktop\users.txt
$var = Get-Content C:\Users\A570654\Desktop\users.txt
Set-Content -Path C:\Users\A570654\Desktop\notes.txt "*************************************************
$var
*************************************************"
Invoke-Item -Path C:\Users\A570654\Desktop\notes.txt
}
############################## FORMS #######################################
$Users = New-Object System.Windows.Forms.RichTextBox
$Users.Size = New-Object System.Drawing.size(470,85)
$Users.Location = New-Object System.Drawing.Size(10,100)
$Users.MultiLine = $true
$Users.AutoSize = $true
$Users.ScrollBars = "Vertical"
$users.AcceptsTab
$form = New-Object system.windows.forms.form
$form.size = New-Object system.drawing.size(600,600)
$button = New-Object system.windows.forms.button
$button.text = "Get Notes"
$button.Add_Click({Notes})
$form.Controls.Add($Users)
$form.Controls.Add($button)
$form.Showdialog()
The reason why I decided to save the string in file is that output shows spaces as in picture 2. If I decide not to save output to file and then get its content then string appears in the following format: JohnTomKate.
You are saving the user input to a file and reload the content which will give you the current output. So just use the variable without reassigning it:
$var = $Users.Text
$var | Out-File C:\Users\A570654\Desktop\users.txt
Set-Content -Path C:\Users\A570654\Desktop\notes.txt "*************************************************
$var
*************************************************"
Output:
*************************************************
John
Tom
Kate
*************************************************
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With