Skip to content

Instantly share code, notes, and snippets.

@jbratu
Last active July 21, 2023 02:00
Show Gist options
  • Select an option

  • Save jbratu/0c4183d12d0a401940c353a2d2b96c8e to your computer and use it in GitHub Desktop.

Select an option

Save jbratu/0c4183d12d0a401940c353a2d2b96c8e to your computer and use it in GitHub Desktop.
#Tail a file
get-content -Tail 20 -Wait -path '.\log.txt'
#Tail and grep a file
Get-Content log.txt -tail 20 –wait | Select-String 'look for string'
#Grep a file
get-content -path '.\log.txt' | Select-String 'look for string'
#Move files older than 180 days
get-childitem -Path "c:\some\log\dir" | where-object {$_.LastWriteTime -lt (get-date).AddDays(-180)} | move-item -destination "c:\some\archive\dir"
#Move files before a certain date
get-childitem -Path "C:\some\log\dir" | where-object {$_.LastWriteTime -lt [datetime]"1/1/2019"} | move-item -destination "c:\some\archive\dir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment