Created
August 8, 2017 11:04
-
-
Save KirillPashkov/6d2dfede89975016b688266e679b61ef to your computer and use it in GitHub Desktop.
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
# 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