Save with Encoding in Visual Studio

Hi,

This post shows how you can save files while retaining their encoding and line endings format. For example, if you’re writing a shell script that will be run on a UNIX operating system, the script is supposed to have line endings as (LF) while Windows’ line endings usually follow (CR)(LF) convention.

So to save a file with its encoding, you need to click on Save As… and then click on the arrow beside the save button as shown below and click on Save with Encoding.

After selecting the file location, VS will show the encoding window where we can select the required encoding. Select the required encoding and click on save. This will save the file with the selected encoding.

Other editors like Notepad++, sublime editor also provide similar options for setting line endings. Personally, I prefer Notepad++. However, best option to prevent line endings to get changed by mistake when moving the script from Windows machine to Unix like System is to use the VI editor within the Unix system itself to avoid the /bin/bash^M: bad interpreter: error message.

Hope this helps!

Advertisements
Posted in General | Tagged , , , , , , , , , , | Leave a comment

Shell script with 10+ parameters? Remember this….

Hi,

This post is mainly aimed towards shell script newbies like myself and the goal is that they don’t end up wasting time on this as I had to.

So, if you are creating a new shell script that requires 10 or more parameters, you need to remember one thing that you can’t access the 10th and further parameters by just $10 or $11, etc.

If you simply put something like below,

...
TenthParameter=$10
EleventhParam=$11
echo $TenthParameter
echo $EleventhParameter
...

The output would actually look like below: (Assume First’s parameter’s value is “First”)

First0
First1

and NOT the actual values of the tenth and eleventh parameters.

This is because the bash interpreter first sees $1 (in the “$10”) and replaces its value immediately.

To get the value of parameters from and beyond 10th param, you need to put them in Curly {} braces as shown below

...    // # WORKS!
...
TenthParameter=${10}
EleventhParameter=${11}
echo $TenthParameter
echo $EleventhParameter
...

This would print the actual values of the parameters.

Hope this helps!

Posted in General | Tagged , , , , , , , , | Leave a comment

Get output of script executed as part of Set-AzureRmVMCustomScriptExecution cmdlet

Hi,

This post explains how to retrieve the output of the script that is executed as part of Set-AzureRmVMCustomScriptExecution cmdlet.

The cmdlet adds a custom script virtual machine extension to a virtual machine. It lets users run custom scripts on the virtual machine. Now in order to retrieve the output if any, of the script that is executed, we can use the Get-AzureRmVMDiagnosticsExtension cmdlet with the -Name and -Status switch. Name holds the name of the custom script vm agent that was installed previously. Also, it is important to use the -Status switch here otherwise we won’t be able to retrieve the output.

You can see that the SubStatuses property of the output of this cmdlet is of importance here and that this holds the output of the script that got executed for the above Set-AzureRmVMCustomScriptExecution cmdlet.

This property is an array which has 2 elements. First holds the output from StdOut stream and second from the StdErr stream. In this case, we’re interested in the StdOut stream.

As you can see, the “Message” property holds the output of the script that got executed on the VM as part of the CustomScript Execution cmdlet. In this case, it is just sample output.

If you’re looking for any errors, you can refer to the StdErr stream using SubStatuses[1] array element.

A Catch here! An important one too!

If you’re running this code as part of an Azure Automation runbook of type “Workflow“, then remember that the cmdlet output is not an object but it’s just the names of the types. So the SubStatuses[0] will only return the name of the TYPE of the property and NOT the actual object. This is how workflows are designed. So if you still want to retrieve the value, you need to execute this within an InlineScript tag as shown below. Click on picture to see clearly.

After the InlineScript tag completes execution, the variable $Result holds the value that is returned from the inline script tag, in this case, the output of the script executed as part of Custom Script execution cmdlet.

Hope this helps!

Posted in .NET, PowerShell | Tagged , , , , , , , , | Leave a comment

Get-AutomationVariable Vs Get-AzureRmAutomationVariable

Hi,

I finally started working on PowerShell and so thought that documenting my learnings here would be useful. So in this post, we will see the difference between the 2 cmdlets Get-AzureRmAutomationVariable and Get-AutomationVariable.

So let’s see the outputs of the two cmdlets. First, Get-AzureRmAutomationVariable

As you can see, when we just run this cmdlet directly, it asks for the resource group name and automation account name. Once these are provided, it lists all the variables that are present in the automation account along with properties of each of the automation variable.

There is also an option to get details of a particular automation variable by adding the         -Name parameter and providing the name of the automation variable. This retrieves the details of only that variable as shown below.

Now coming to the second cmdlet, Get-AutomationVariable. This cmdlet directly gives the value of the automation variable as shown below.

This can be used when we only need the value without any other details of the variable.

Hope this helps!

Posted in PowerShell | Tagged , , , , | Leave a comment

Enable TLS1.1 and TLS 1.2 in Fiddler

Hi,

This post will explain how you can enable TLS 1.1 and TLS 1.2 in fiddler so you can test your Web Apis with TLS 1.1 or 1.2. In order to do this, navigate to

Tools --> Options --> HTTPS

You will see the below screen

If Decrypt HTTPS traffic is not enabled, enable it and see what is shown in Protocols. If you do not see tls1.1;tls1.2, then click on the protocols and add the below line in the pop-up.

tls1.0;tls1.1;tls1.2

Click OK. Ok again. Then restart fiddler for changes to take effect.

Now all the further requests that you make from Fiddler will have TLS1.1 and 1.2 support.

Hope this helps!

Posted in General | Tagged , , , , , | 2 Comments

An easy to miss gotcha in Azure Service Fabric service with multiple listeners

Hi,

If you’ve ever worked with Azure Service Fabric, then there is a high probability that you will have a service that creates multiple listeners, either to multiple ports to accept requests from different protocols or listeners to Azure services like service bus or IotHub.

In this case, you might have to create multiple communication listeners in your application. While doing this, there is a chance that you might miss one small thing which would eventually result in you getting the following error in the Service Fabric Explorer

As you can see in the error message, it says that a Unique name must be specified for each listener when multiple listeners are used. We can specify this name as the second parameter of ServiceInstanceListener class as shown below.

This will solve the error.

Hope this helps!

Posted in .NET, C# | Tagged , , , | Leave a comment

CSS Browser Compatibility settings in Resharper

Hi,

This post will show you how we can enable/disable browser compatibility settings for CSS in Resharper. This setting is very useful which shows us clearly whether a particular css selector or other css features are compatible with specific versions of browsers or not. See the example below.

We can see here that resharper points out specifically by highlighting the selector saying it is not compatible with IE 8.0.

We can enable this setting by navigating to Resharper menu item –> Options –> Code Editing –> CSS –> Inspections

As you can see, we have the option of enabling the check for browser compatibility along with multiple browsers as well as minimum version for the browser.

For more such useful information, do refer the below site.

https://blog.jetbrains.com/dotnet/2013/07/30/css-support-improvements-in-resharper-8/

Hope this helps!

Posted in .NET, General | Tagged , , , , , , | Leave a comment