Powershell Split Text into Individual Lines


Powershell Split Text into Individual Lines

Inline

$list = @"
server1
server2
server3
server4
server5
server6
server7
"@

$regex = '[\r\n]{1,}'
$new = $list -split $regex

$new | measure
Count             : 7

External File

$list = Get-Content list.txt
$new | measure
Count             : 7
  • https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_regular_expressions?view=powershell-7.1