Skip to content

Instantly share code, notes, and snippets.

@flq
Created August 10, 2010 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flq/516830 to your computer and use it in GitHub Desktop.
Save flq/516830 to your computer and use it in GitHub Desktop.
pieces regarding powershell usage
$a = pwd
ls -r |
? { !$_.name.Contains(".g.") } |
? { $_.Extension -eq ".cs" -or $_.Extension -eq ".csproj" } |
? { $_.lastwritetime -gt [DateTime]::Now.AddHours(-6) } |
% {
$relative = $_.fullname.Replace($a.Path + "\","")
$Path = [System.IO.Path]::GetDirectoryName($relative)
mkdir c:\temp\$path -erroraction SilentlyContinue
Copy-Item -path $relative -destination c:\temp\$path
}
function regex([string]$pattern) {
New-Object -TypeName System.Text.RegularExpressions.Regex -ArgumentList $pattern
}
$dateMatch = regex "\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d"
Set-Variable -scope Global -name DATEMATCH -Value $dateMatch
function toDate([string]$line) {
$m = $DATEMATCH.Matches($line)
if ($m.Count -eq 0) { return }
$dateString = $m[0].Value
[DateTime]::ParseExact($dateString, "yyyy-MM-dd HH:mm:ss", [System.Globalization.CultureInfo]::InvariantCulture)
}
function runExceptionCheck {
dir *.log | ? { $_.LastWriteTime -gt [DateTime]::Now.AddDays(-5) } | Select-String -Pattern "Uncaught exception" |
Add-Member -Name AsDateTime -MemberType ScriptProperty -Value { toDate $this.Line } -PassThru |
Sort-Object -Property AsDateTime -Descending
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment