Save commands in a .ps1 file. By default Windows blocks scripts, so allow your own (and signed downloaded ones) for your user only.
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned # cleanup.ps1: delete temp files older than 7 days $limit = (Get-Date).AddDays(-7) Get-ChildItem $env:TEMP -Recurse -File | Where-Object LastWriteTime -lt $limit | Remove-Item -ErrorAction SilentlyContinue .\cleanup.ps1