Code snippets : Windows : Importing Event Logs to Database


Code snippet from old archives. It shows how to import Windows event log entries to database. Important is to setup database and table accordingly, so it contains apropriate columns.

Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
objConn.Open "DSN=EventLogs;"
objRS.CursorLocation = 3
objRS.Open "SELECT * FROM tblEventLog" , objConn, 3, 3
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRetrievedEvents = objWMIService.ExecQuery _
("Select Category, CategoryString, ComputerName, Data, EventCode, _
EventIdentifier, EventType, LogFile, Message, RecordNumber, SourceName, _
TimeGenerated, TimeWritten, Type, User from Win32_NTLogEvent")
For Each objEvent in colRetrievedEvents
objRS("el_Category") = objEvent.Category
objRS("el_CategoryString") = objEvent.CategoryString
objRS("el_ComputerName") = objEvent.ComputerName
objRS("el_Data") = objEvent.Data
objRS("el_EventCode") = objEvent.EventCode
objRS("el_EventIdentifier") = objEvent.EventIdentifier
objRS("el_EventType") = objEvent.EventType
objRS("el_LogFile") = objEvent.LogFile
objRS("el_Message") = objEvent.Message
objRS("el_RecordNumber") = objEvent.RecordNumber
objRS("el_SourceName") = objEvent.SourceName
objRS("el_TimeGenerated") = objEvent.TimeGenerated
objRS("el_TimeWritten") = objEvent.TimeWritten
objRS("el_Type") = objEvent.Type
objRS("el_User") = objEvent.User

Tips & Tricks : Elasticsearch and Java insufficient memory


By default elasticsearch has 2GB of RAM set for JVM. In case you run it on VM with less memory you need to change:

  • Xms2g to –Xms512m
  • Xmx2g to –Xmx512m

in /etc/elasticsearch/jvm.options configuration file.


Config snippets : Cisco : Redirect console output to telnet session


This is one of those things I always forget when is needed. How to redirect console output to telnet session when debugging something on Cisco device.

So, not to forget it I record it for future reference (I guess from now on I will remember that, but well.. what you do… just Murphy’s law)

From telnet session just issue command shown below, and all debug logs will be redirected to telnet session.

R1#terminal monitor

Games : Codes : Skyrim – finding Lydia


I’m a big fan of Skyrim 🙂 so, sometimes I will put some codes and clues for that game.

If for some reason you have to leave Lydia and take another person with you and then you want to bring Lydia back you can speed up that process using codes.

  • player.moveto a2c94 – will bring you to current Lydia location
  • a2c94.moveto player – will bring Lydia to your current location

You might have to split up with Lydia if you need to hire someone else temporarily like in Boethiah quest.


Code snippet : Sending email from PowerShell script


If you want to send email from PowerShell script via Google Mail:

$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$SMTPUsername = "sender@gmail.com"
$SMTPPassword = "password"

$EmailSenderAddress = New-Object System.Net.Mail.MailAddress("sender@gmail.com", "PowerShell Automated Email")

$EmailFrom = $EmailSenderAddress
$EmailTo = "recipient@gmail.com"
$EmailCc = "recipient@hotmail.com"
$EmailAttachment = "C:\Scripts\Attachment.txt"
$EmailSubject = "Automated Email with Report."
$EmailBody = @"
Please find attached report.

$EmailMessage = New-Object System.Net.Mail.MailMessage
$EmailMessage.Subject = $EmailSubject
$EmailMessage.Body = $EmailBody
$EmailMessage.From = $SMTPUsername

$SMTPSession = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$SMTPSession.EnableSSL = $true
$SMTPSession.Credentials = New-Object System.Net.NetworkCredential($SMTPUsername, $SMTPPassword);
Write-Host "Mail Sent"

How-to : Connect to Amazon EC2 Linux AMI using SecureCRT


Recently I decided to use Amazon AWS EC2 platform to host systems in the Cloud. As operating system I needed is Linux I quickly deployed Amazon Linux AMI, which is quick and simple to do.

Once instance was created I downloaded key pair. Now it came down to connecting to my virtual machine in the cloud.My SSH client of choice is SecureCRT. Let’s see how to configure session parameters in SecureCRT in order to connect to Amazon Linux AMI instance hosted on EC2 platform.

I’m using SecureCRT 7.0.1 to connect to server hosted on Amazon EC2 platform.



Tips & Tricks : xcrun: error after upgrading to macOS Mojave


After upgrading to macOS Mojave you might experience following error when trying to run some command line tools like git, for example:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

To resolve that run those commands in Terminal:

sudo xcode-select --switch /Applications/Xcode.app
sudo xcode-select --switch /Library/Developer/CommandLineTools

Issue should be resolved.




Code snippets : Restart IIS Application Pool in PowerShell


If you need to watch IIS application pool and start it once goes down and want to use PowerShell for that here is simple script for that.

Script includes also logging all restarts in log file which is created in same folder as script.

# AppPool to monitor
$AppPoolName = "AppPoolName"

# Log Destination
$LogToScreen = 1
$LogToFile = 1

# Determine script location for PowerShell
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path

# Output log
$OutputLogPath = $ScriptDir + "\AppPoolRestart.csv"

#Check if file exists and create if it doesn't
If(!(Test-Path -Path $OutputLogPath)){
#Create file and start logging
New-Item -Path $OutputLogPath -ItemType File

# Function: LogMessage
function LogMessage($Msg, $ToScreen, $ToFile)
if ($ToScreen -eq 1)
Write-Host $Message

If ($ToFile -eq 1)
Add-Content -Path $OutputLogPath -Value $Message
# End Function: LogMessage

While (1 -eq 1){


$AppPoolStatus = Get-WebAppPoolState -Name $AppPoolName

$DateTime = Get-Date

If ($AppPoolStatus.Value -eq "Stopped"){
Write-Host "Not Working"
Start-WebAppPool -Name $AppPoolName
$Message = "App Pool $AppPoolName restarted at $DateTime"
LogMessage $Message $LogToScreen $LogToFile
Write-Host "Working"

Sleep 5

Tips & Tricks : SQL Server “Cannot connect to WMI provider”


Recently I had issue which occured without any particular reason on SQL Server 2012. All of the sudden I start getting error message:

Cannot connect to WMI provider. You do not have permission or the server is
Note that you can only manage SQL Server 2005 servers with SQL
Server Configuration Manager.
Invalid Namespace.

when tried to run SQL Server Configuration Tools.

What resolved situation is command:

mofcomp C:\Program Files\Microsoft SQL Server\100\Shared\sqlmgmproviderxpsp2up.mof

Code snippets : VBscript : Change My Computer icon description


Script changes description of My Computer icon to display Computer: ComputerName

Can be very handy when troubleshooting computer remotely when we require user to tell us name of the computer user works on.
Script works on Windows 2000/XP/Vista/7.