Remove multiple lines from a file

Hi,

I have a script that writes a transcript log. I would like to remove the entire header from the log file, it’s always the same header length:


Windows PowerShell transcript start
Start time: 20210210154834
Username: TESTLAB\administrator
RunAs User: TESTLAB\administrator
Configuration Name:
Machine: CA01 (Microsoft Windows NT 10.0.17763.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 7456
PSVersion: 5.1.17763.1490
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.1490
BuildVersion: 10.0.17763.1490
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1

PS 6.2 has a parameter called -UseMinimalHeader to make the header shorter but I also need this with PS 5.1.
Does anybody know how I can remove the lines? Tried something with Get-Content -replace

Thanks!

If you know exactly how many lines you want to exclude, you could use Select-Object -Skip to omit them.

$file = New-TemporaryFile

@'
Windows PowerShell transcript start
Start time: 20210210154834
Username: TESTLAB\administrator
RunAs User: TESTLAB\administrator
Configuration Name:
Machine: CA01 (Microsoft Windows NT 10.0.17763.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 7456
PSVersion: 5.1.17763.1490
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.1490
BuildVersion: 10.0.17763.1490
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1

want only this line and below
another line

a third line
'@ | Set-Content $file

(Get-Content $file) | Select-Object -Skip 17 | Set-Content $file

Get-Content $file

The output (aka the new contents of the file) is

want only this line and below
another line

a third line