Existem várias maneiras de fazer a pesquisa rápida na Web usando…
Powershell 'dividir um arquivo no feed de linha'
... retornaria vários hits.
Pode ser tão simples quanto usar os cmdlets New-Item, Get-Children e Add-Content usando um loop e uma condição.
$Lines = Get-Content 'D:\Scripts\$data.txt'
New-Item -Path 'D:\Scripts' -Name 'FileName.txt' -ItemType File
$FileName = (Get-ChildItem -Path 'D:\Scripts\FileName.txt').FullName
$FileCount = 0
ForEach($Line in $Lines)
{
If($Line -ne '')
{
'Appending line to a file'
Add-Content -Value $Line -Path $FileName
}
Else
{
'Empty line encountered - creating new file'
$FileName = New-Item -Path 'D:\Scripts' `
-Name (((Get-ChildItem -Path 'D:\Scripts\FileName.txt').BaseName +
($FileCount = $FileCount + 1) + '.txt')) -ItemType File
}
}
Get-ChildItem -Path 'D:\Scripts\filename*'
# Results
Directory: D:\Scripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 27-Jun-18 12:48 0 FileName.txt
Appending line to a file
Appending line to a file
Appending line to a file
Empty line encountered - creating new file
Appending line to a file
Appending line to a file
Appending line to a file
Empty line encountered - creating new file
Appending line to a file
Appending line to a file
Appending line to a file
-a---- 27-Jun-18 12:48 21 FileName.txt
-a---- 27-Jun-18 12:48 21 FileName1.txt
-a---- 27-Jun-18 12:48 21 FileName2.txt