Jon Do
Jon Do

Reputation: 39

How to enter new line to html with Powershell

I have a PowerShell script that opens an IE browser and fill a form. I also have an csv file with phone numbers. how can I insert each phone number to new line on the value tag?

tried already:

$phoneBox = $IE.Document.getElementById($phonesID)
$phones = Get-Content -Path "c:\phones.csv"
foreach($p in $phones)
{
   $phoneBox.value += "<br>" + $p + "<\br>" 
}

and also:

$phoneBox = $IE.Document.getElementById($phoneID)
$phones = Get-Content -Path "c:\phones.csv"
foreach($p in $phones)
{
   $phoneBox.value += $p + "\n" 
}

and also:

$phoneBox = $IE.Document.getElementById($phoneID)
$phones = Get-Content -Path "c:\phones.csv"
foreach($p in $phones)
{
   $phoneBox.value += $p + "&#13;" + "&#10;" 
}

EDIT:

The Html element I AM REFERING TO IS:

<textarea name="ctl00$MainContent$reciSel$TabsContacts$tabFromFile$txtFromFile" tabIndex="0" id="ctl00_MainContent_reciSel_TabsContacts_tabFromFile_txtFromFile" style="width: 98%; height: 386px; overflow-x: hidden;" onkeyup="PhoneNumbersTxt_onChange(this.value);" onkeypress="AddNewLine(this,event);" rows="2" cols="20" wrap="off" autocomplete="off">Here I need to enter each number to new line</textarea>

Upvotes: 0

Views: 5829

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200503

Literal whitespace is not parsed as formatting information in HTML (all consecutive whitespace is collapsed to a single space in the output).

Either put each phone number in a separate paragraph

$phoneBox.value += '<p>' + $p + '</p>'

or (if you want it in a single block element with a linebreak after each entry) put a single <br> (or <br/> if you want valid XHTML) after the number:

$phoneBox.value += $p + '<br>'

That does not apply to the content of textareas, though. For those you add linebreaks like this (LF only):

$phoneBox.value += $p + "`n"

or like this (CR-LF):

$phoneBox.value += $p + "`r`n"

PowerShell escape sequences start with a backtick, not a backslash.

Upvotes: 1

Related Questions