PowerShell keep printing 1 before expected output

By | 2017-05-15T10:26:40+00:00 May 15th, 2017|languages, Scripts|

I had written a script to parse the contents of a URL and store the contents in a SQL Server table. The script has a couple of write-host commandlets to track the progress of the script. Here is a snippet of the script. [crayon-59c7b9181e17b002851761/] However on executing the script, before the write-host commandlet a couple of "1" would be written in the console. I had nowhere written in the script to write "1" to the console! On having a closer look, I realized that the SqlCommand.ExecuteNonQuery method was the culprit. Here is why. As per the documentation, the return value of SqlCommand.ExecuteNonQuery method will always be the number of [...]

AutoHotKey | Script fails with variable name contains an illegal character

By | 2017-04-05T17:56:28+00:00 April 5th, 2017|Scripts, tools|

I am a big fan of automating routine tasks. When I work on Windows AutoHotKey scripting language is my go-to tool for automation. With AutoHotKey one can automate just about anything on Windows. While working on one such scripts, I encountered the following problem. [crayon-59c7b91822239064731935/] As seen in the above error message, in line 14 I am splitting a variable with text values (delimited by ".") and assigning the output to an array called word_array. Now the script is complaining that the variable name has an illegal character i.e.TheWindowsUser which is the value I had assigned to the variable UserName. For a moment I was puzzled how the variable is [...]

Always execute a program as a different user on Windows

By | 2017-03-26T15:47:25+00:00 March 29th, 2017|operating systems, Scripts, tools, Windows|

I like to create new scripts and automate the routine work. In order to test the scripts, at times I would like to execute those scripts under the credentials of a different users. In order to make my job easy, I would create a shortcut for that script. Run as a different user option in Windows GUI is a good option but the problem with this approach is that I need to enter the credentials of the users on each occasion. In this post I will explain how I create a shortcut for a program so that it runs as a different user but does not prompt [...]

Resolved | Uncaught Error: Call to undefined function mysqli_connect() in /var/www/html/index.php

By | 2017-03-20T21:23:08+00:00 March 23rd, 2017|AWS, Linux, Scripts|

I was using the following PHP file to test connectivity of MySQL instance hosted on Amazon RDS. [crayon-59c7b91827595008026419/] A very basic script indeed. However when I try to browse this file from the web browser, I would get the following error. What a message to troubleshoot! Since this page was hosted on an Apache server, the first place to look for is the Apache log. Hence executed the following command to check Apache logs. [crayon-59c7b918275a4707984455/] [crayon-59c7b918275ac299289998/] This made more sense. Line 5 in my code is calling mysqli_connect() function but Apache did not recognize it. That's when I remembered that I did not install the [...]

Connect to a database on RDS using PHP

By | 2017-03-20T11:30:02+00:00 March 19th, 2017|cloud, data, Scripts|

In my previous post, we created a MySQL instance on Amazon RDS. We will launch a PHP page from a EC2 instance and connect to the newly created MySQL instance. As I mentioned in the last post, I had disabled Public access to the MySQL instance as I wanted only my application to connect to it. Hence for my application to connect to the MySQL instance, first I need to allow inbound connections to port 3306 from my EC2 instance which will host the Apache server. For this I need to edit the properties of the Security Group to which the MySQL instance belongs to. The [...]

Extract counters from Perfmon files (.blg) through PowerShell

By | 2017-03-15T10:21:36+00:00 March 7th, 2017|Scripts|

I was working on Performance baselining a server. In order to understand server's performance a Performance Monitor data collector was configured. Since this data collector ran for a week's time, the number of performance monitor files collected increased dramatically. I ended up with more than 700 .blg files. I was interested in few counters namely CPU, Memory, Load on the drives out of the 100 counters that were present in those BLG files. One option that I had was to use relog.exe. However my options would be limited to the parameters provided by relog.exe. Hence I decided to write a PowerShell script to get the work done. [...]

Powershell script failing with “cannot be loaded because the execution of scripts is disabled on this system” error

By | 2017-03-15T10:24:36+00:00 March 6th, 2017|Scripts, tools, Windows|

On a brand new Windows Server I was trying to execute a PowerShell script. On executing it failed with the following error. PS C:\Users\> D:\ReadPowerShell.ps1 File D:\OneDrive\work\ReadPerfmon\ReadPowerShell.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details. I got this error because by default PowerShell restricts the executing of the scripts on a given machine. To resolve this error, we need to set the execution policy on the machine using Set-ExecutionPolicy cmdlet. More details about this Cmdlet are documented at this article. Since this machine is my development box, I decided to set the execution policy to unrestricted. The [...]

Bulk rename files recursively on Windows using PowerShell

By | 2017-03-15T10:36:53+00:00 February 25th, 2017|Scripts|

Recently I was working on historical performance analysis of a server. I had few hundreds of Performance Monitor counter files (.blg) to go through. The problem that I had was these BLG files same file name but they were located in hundreds of folders. To analyze them, I'd prefer them to be in one folder. To achieve this I had to rename them first and then move them to a common folder. The following PowerShell script helped me rename all the files in one go. [crayon-59c7b9182c6c2156055523/] In short, this is what the script does. Assign a value of 1 to a variable $p Get the [...]