Skip to content

Instantly share code, notes, and snippets.

@thecfguy
Created June 13, 2019 09:34
Show Gist options
  • Save thecfguy/1d964b68912cb9210515c2f142ea0ed8 to your computer and use it in GitHub Desktop.
Save thecfguy/1d964b68912cb9210515c2f142ea0ed8 to your computer and use it in GitHub Desktop.
# Powershell script to list all files (including sub directory) under particular directory and remove last line out of it.
Get-ChildItem ".\" -Recurse -Filter *.txt |
Foreach-Object {
$lastline = Get-Content $_.FullName | select -Last 1
if ($lastline -like 'findsomestring') {
$test = Get-Content $_.FullName
$output = $test[0..($test.count - 2)]
Set-Content -Path $_.FullName -Value $output
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment