Last active
July 21, 2023 02:00
-
-
Save jbratu/0c4183d12d0a401940c353a2d2b96c8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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