Skip to content

Instantly share code, notes, and snippets.

@belotn
Created July 9, 2013 14:41
Show Gist options
  • Save belotn/5957878 to your computer and use it in GitHub Desktop.
Save belotn/5957878 to your computer and use it in GitHub Desktop.
Load an SQLite DB with filtered and modified content from eventlog
get-eventlog -LogName "Key Management Service" -ComputerName "COMPNAME" -InstanceId 1073754114 | select Index,Message |% {if ($_.MEssage -match ".*(0x[0-9a-f]+),(\d+),([^,]+),([0-9a-f\-]+),([^,]+),(\d),(\d),(\d+),([0-9a-f\-]+).*") { $_ | Add-Member -type NoteProperty -name Client -Value $matches[3] -Passthru | Add-Member -type NoteProperty -name CMID -Value $matches[4] -PassThru | Add-Member -type NoteProperty -name ErrorLevel -Value $matches[1] -PassThru| Add-Member -type NoteProperty -name MinCount -Value $matches[2] -PassThru| Add-Member -type NoteProperty -name DateDemand -Value $matches[5] -PassThru | Add-Member -type NoteProperty -name isVM -Value $matches[6] -PassThru| Add-Member -type NoteProperty -name State -Value $matches[7] -PassThru | Add-Member -type NoteProperty -name TTLmin -Value $matches[8] -PassThru | Add-Member -type NoteProperty -name LicenseId -Value $matches[9] -PassThru} } | select @{N="Id";E={$_.Index}},Client,CMID,ErrorLevel,MinCount,DateDemand,isVM,State,TTLmin,LicenseId |% { new-item -path mydb:/Leases -ComputerId $($(if(ls mydb:/Computer -filter "CMID='$($_.CMID)'"){ls mydb:/Computer -filter "CMID='$($_.CMID)'"} else { new-item mydb:/Computer -ComputerName $_.Client -CMID $_.CMID -isVM $_.IsVM }) |select ComputerId).ComputerId -LicenseRow $($(if(ls mydb:/Licence -filter "LicenseID='$($_.LicenseID)'"){ls mydb:/Licence -filter "LicenseID='$($_.LicenseID)'"} else { new-item mydb:/Licence -LicenseId $_.LicenseId -MinCount $_.MinCout }) |select LicenseRow).LicenseRow -DateDemand $_.DateDemand.replace('/','-') -State $_.State -TTLMin $_.TTLMin -ServerName "COMPNAME" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment