Skip to content

Instantly share code, notes, and snippets.

View PsCustomObject's full-sized avatar
🏠
Working from home

Daniele Catanesi PsCustomObject

🏠
Working from home
View GitHub Profile
@PsCustomObject
PsCustomObject / Remove-OldFiles.ps1
Created December 28, 2018 07:56
PowerShell Remove Older Files
# Define variables
[string]$filePath = 'C:\TestCleanup\'
[string]$fileExtension = '*.log'
[int]$fileAge = 90
[datetime]$ageTimeSpan = (Get-Date).AddDays(-$fileAge)
# Get all matching files
[array]$filesToPurge = Get-ChildItem -Path $filePath -Filter $fileExtension -File |
Where-Object { $_.LastWriteTime -lt $ageTimeSpan }
@PsCustomObject
PsCustomObject / Set-StopWatch.ps1
Created December 26, 2018 18:52
PowerShell Measure Script Exeuction time via StopWatch
# Full post https://pscustomobject.github.io/powershell/how%20to/PowerShell-Measure-Execution-Time/
# Full Type Name would be System.Diagnostics.Stopwatch
# Start the stopwatch
$stopWatch = [Diagnostics.Stopwatch]::StartNew()
# Define search path
[string]$userFolder = 'Users/PsCustomObject/Desktop/'