Update PowerShell to 5.1 on Windows server 2012R2

As of Aug 2017, googled the link to download the latest version 5.1 and found below:
Powershell 5.1 on microsoft site. Refer figure below
2

Click on download button to move to next page and select the appropriate .msi to download.

“W2K12-KB3191565-x64.msu” may be the file you choose for download and run. So i did
the same and found the error that this may not be the correct setup to run.
Read on article to choose the correct file on
Powershell on Win server 2012 R
Went back to download page and this time downloaded the file as per below snapshot:

and executed it. It ran successfully.

Azure Fabric service

To build always-on, scalable, distributed applications in azure from your development machine, you need to ensure right tools are already installed.

This blog is to install tools for VS 2017.

While installing or modifying VS 2017 on your development machine ensure option ‘Azure development’ is checked on.

Azure Components in VS 2017

Apart from this you need Microsoft Azure Service Fabric SDK on your machine. The SDK gets installed using Web installer 5.0. The link for SDK is:

MicrosoftAzure-ServiceFabric-CoreSDK

 

Fabric SDK installation step

 

Fabric SDK installation step succeed

Visual studio is now ready to allow you create service fabric applications.

Goto File–>New–>Project–>Cloud

Visual studio 2017 Service Fabric template

Choose the service you want to create:

Visual studio 2017 Service Fabric template selection

Connect MySQL db using Powershell

The purpose of this blog is to get the dev aware of how the PowerShell can be used to connect to MySQL db and insert a sample record.

With the increase of automation in industry, powershell is made responsible for doing many more things including inserting a new record in MySQL database.

The script flow start  at line 28 by setting bthe username/ password/ database name, server name of the MYSQL database. By Default the port to connect db is 3306.
$query parameter of powershell need to be set for correct insert DML statement.
Next is Powershell function call which takes username, password, server, database, query as parameter. Line 1 to 26 is PowerShell function which handles this.

For this function to work perfectly it necessary for[reflection.assembly]::LoadFrom(“C:\abc\MySql.Data.dll”)

Statement to execute with success. What this statement do is load MySQL.data.dll assembly in script.

Its >net and MySQL connector Dll. You can get this dll by creating a new project in .Net Visual studio and add a new package by searching ‘MySQL’. Make sure you correctly set this DLL path in script.
This function takes care of establishing the connection with MySQL, Open the connection, execute the SQL DML query and return the response.
I tested this script in Windows 10, Powershell 4 and MySQL 8.4.5 and works fine.
The script can be downloaded from: https://1drv.ms/u/s!AuanYRI1Vj_XgyHzrT3AlobAor2a

.Net framework version the assembly was created in

string assemblyPath = @”<exe/ dll path>”;

var assembly = Assembly.LoadFrom(assemblyPath);

var customAttributes = assembly.GetCustomAttributesData();

var dotnetFramework = customAttributes.FirstOrDefault(attr => attr.AttributeType.Equals(typeof(TargetFrameworkAttribute)));

var frameworkVersion = string.Empty;

if (null != dotnetFramework)

{

if (dotnetFramework.ConstructorArguments.Any())

{

// first argument is the name of the framework.

frameworkVersion = (string)dotnetFramework.ConstructorArguments[0].Value;

}

}

Console.WriteLine(“Framework Version: “ + frameworkVersion);

 

This code will give you the .Net framework version the dll/exe was created in.

 

I tested it for 4.5, 4.6.1 , 4.5.2 and gives the correct info.