Created
August 10, 2010 07:06
-
-
Save flq/516830 to your computer and use it in GitHub Desktop.
pieces regarding powershell usage
This file contains 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
$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 | |
} |
This file contains 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
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