Skip to content

Instantly share code, notes, and snippets.

@KirillPashkov
Created August 8, 2017 11:04
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 KirillPashkov/6d2dfede89975016b688266e679b61ef to your computer and use it in GitHub Desktop.
Save KirillPashkov/6d2dfede89975016b688266e679b61ef to your computer and use it in GitHub Desktop.
# Check to see if we are running the 64 bit version of Powershell.
# See http://stackoverflow.com/questions/2897569/visual-studio-deployment-project-error-when-writing-to-registry
if ([intptr]::size -eq 8) {
$mongoDriverPath = (Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v3.5\AssemblyFoldersEx\MongoDB CSharpDriver 1.2").'(default)';
}
else { $mongoDriverPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\.NETFramework\v3.5\AssemblyFoldersEx\MongoDB CSharpDriver 1.2").'(default)'; }
Add-Type -Path "$($mongoDriverPath)\MongoDB.Bson.dll";
Add-Type -Path "$($mongoDriverPath)\MongoDB.Driver.dll";
$db = [MongoDB.Driver.MongoDatabase]::Create('mongodb://localhost/powershell');
$collection = $db['eventlogs']
$collection.Drop();
Get-EventLog -List | ForEach-Object {
Get-EventLog $_.Log -After '01.01.2017' | ForEach-Object {
$collection.Insert(@{
HostName = $Env:COMPUTERNAME;
Log = 'Application'
Index = $_.Index;
Time = $_.Time;
EntryType = $_.EntryTime;
Source = $_.Source;
InstanceId = $_.InstanceId;
Message = $_.Message;
}, [MongoDB.Driver.SafeMode]::True) > $null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment