//Cloud notes from my desk -Maheshk

"Fortunate are those who take the first steps.” ― Paulo Coelho

How to collect Azure Cloud Service(VM) Logs using Powershell

Issue: 

How to collect the “Azure Cloud Services instances(VM) logs” when we are unable to RDP or connection failed for some reason. Infact, we can try when RDP not configured etc. Just in case, If we see RDP working, then we can use this tool in VM directly after logging in- http://dsazure.blob.core.windows.net/azuretools/AzureTools.exe

The below solution is useful when we are unable Remote desktop(RDP) into Azure Cloud Service VM machines.

Solution: 

I am trying to simplify this blog post and also adding those missing script location for quicker reference.

Step 1: Download this <click here> scripts to your c:temp. [ AzureRemotelogcollector.ps1, SetAzureServiceLogCollector.ps1 ]

Step 2: Extract the files to the location say C:temp and update the required details in this file -AzureRemotelogcollector.ps1 { make sure to enter cloud services name, role and more importantly working storage account 🙂 }

Step 3: Launch the Powershell in admin mode ( how to launch any exe in admin mode easily refer here )

Step 4: Run this cmdlet to access your subscription PS C:windowssystem32> Add-AzureAccount 

Step 5: Navigate to our script file location path and then type the filename for execution PS C:temp> .AzureRemotelogcollector.ps1

 

 

Step 6: Now its ready for download. You can use this free tool http://storageexplorer.com/ to download these log files

Let me know if you run into any issues..

Related links:-

Configure your Azure Subscription with the Azure PowerShell Cmdlets. 

Regarding troubleshooting tools- refer Kwill’s blog – here 

P.s: I do not author these scripts. Thanks to this site for hosting this script site


<Updated 4/8/2016: Added screenshot explaining the input params>

error

2016-02-18 Posted by | Uncategorized | , , , , | 2 Comments

10 cool things about .NET Core & ASP.NET 5

Yes, you are reading right – Now .NET is truly cross-platform, open-source technology and as many said, it’s no more grandpa’s .NET

Let us start with CLR, CORE and other dependencies one by one. As of now, there are 3 flavors of CLR available – 1) .NET Framework CLR 2) Mono CLR 3) .NET CoreCLR (cloud optimized/pay as you go).

.NET Core consists of set of libraries called “corefx and small runtime called “coreclr”. 

Then “What actually is .NET Core?”

It is nothing but modular, cross platform and open source implementation of .NET Framework means our application can be targetted to run on windows, Linux, Mac OS X and docker.

Let us further break it down; what is what –

corefx –> repo contains .NET Core foundational lib’s alias CoreFx. Let say classes for collections, console or XML for that matter

coreclr –> repo contains the actual .NET Core runtime alias CoreCLR – base library called mscorlib. It also contains GC, JIT compiler and some of the base .NET data types and low level classes like system.tostring, type etc

dnx –> .NET execution runtime, having the code to bootstrap and run our application. It includes compiling system, SDK tools and the native CLR Hosts

dnvm -> enables you to acquire one or multiple .NET Execution Environments (DNX). DNVM is simply a script, which doesn’t depend on .NET. You can install it via a PowerShell command from a command prompt window

dnu -> tool is responsible for all operations involved with packages in your application { dnu restore / dnu install / dnu publish / dnu pack / dnu build / dnu list }

.NET native –> compiles IL byte code to native machine code (no-JIT’ing), so that when the code is executed, there is only “native” code running. It produces binary directly to the OS to execute –no JIT-ing business or runtime compilation. .NET Native is the set of tools used to build .NET Universal Windows platform (UWP) apps.  a.k.a AOT, Ahead of Time compiler. 

.NET Framework and .NET native is currently supported only on Windows OS. One thing to note here, .NET Native doesn’t require .NET Framework runtime dependencies any more. In particular, if you set the .NET native to true then you do not require run time installed. However it uses the optimized implementation of .NET Core.

1) .NET Core runtime includes the same GC which is available in .NET Framework however it doesn’t have things like App Domain, registry or CAS etc. Best thing above all is; isolation– you are going to pack and ship only the run-time dependencies needed for the execution. Means no other external dependencies or shared components required on the targeted machine. We can deploy locally (side by side). It is also sub-set of .NET Framework. We no need to get the latest .NET for system wide installs. We pull the references which is required only for “our” project – that’s it. More importantly, as I said earlier this eliminates GAC installation or registry or COM dependencies or DLL from a installation path – it’s all gone now. It’s pretty much work within the capsule which gets deployed through Nuget.

2) .NET Core story means Mono? “No”, Mono is an open source implementation of .NET Framework. It is alive and well with a large ecosystem on top. It independent of .NET Core.

3) .NET Core is mostly aimed for server applications– say ASP.NET vNEXT. ASP.NET 5/vNEXT (RC1) – fully open source  expected in Q1* 2016, optimized for modern cloud based applications. You can develop and run them across the platforms. It is great fix for Devops and Cloud Computing. With the level of modular separation, it is going to be the trend in development for Containers based micro services or distributed components maintained and updated separately.

4) ASP.NET 5 is based on a new flexible run-time host. It provides a flexibility to run your application with any of the 3 different run-times – .NET framework, .NET Core and Mono. We can host our ASP.NET 5 on IIS, or any Open Web Interface .NET (OWIN)-based server or our own process or self host.

5) No web.config/app.config settings, global.aspx for asp.net 5, more importantly there is no system.web as like traditional asp.net application. Your web config file is replaced with “Project.json” is our project metadata file which holds all the dependencies and framework to build and run etc.

> Start.cs is main file for our application – It has got a Startup constructor and Configuration-services which adds services to the container

> References – all dependencies of our projects are neatly packaged as nuget pkgs.

aa

6) ASP.NET 5 uses built-in Dependency Injection for configuring Services and Libraries. Admin can patch an application without requiring the application to recompile. More over application is also not locked into a patched version – newer versions which is patched can still be used. DI in ASP.NET 5 is end to end applied through .NET Stack.

7) NuGet as a first class delivery vehicle– Yes, packaging is done using NuGet; – pack what we wanted and distributed as independent package.

8) In case of ASP.NET 5, there is no compilation happens means build step is removed. We can make the changes and refresh the browser for new changes to reflect. The compilation happens automatically after save. It also fully supports side by side support, can be installed without affecting any other applications on the machine.

9) .NET Framework is a machine wide framework. Any changes affects all the application taking the dependency on it where as .NET Core is XCOPY deployable stack. We do not have to get any out of the box run-time installed other than what application bundled with. It minimize the size of the application as well.

Step1) Execute the following command in command prompt under Admin
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}" 
Step2) Dnvm upgrade or Dnvm update-self
Step3) dnvm install -r coreclr latest -u
Step4) dnvm list 
Step5) Create the below code in C:tempHello.cs
 using System;
 public class Program
 {
 public static void Main (string[] args)
 {
 Console.WriteLine("Hello, Windows");
 Console.WriteLine("This is from Windows :) and running over .NET Core");
 }
 }
Step6) Create a project.json under the same folder where our CS file resides
{
 "version": "1.0.0-*",
 "dependencies": {
 },
 "frameworks" : {
 "dnx451" : { },
 "dnxcore50" : {
 "dependencies": {
 "System.Console": "4.0.0-beta-*"
 }
 }
 }
}
Step7) dnu restore
Step8) dnx run

10) As of now, we can build few workloads like 1) Console Application 2) ASP.NET 5 and its services 3) Windows 10 UWP. But things are getting added. Read the future .NET Core road map here

Click the gif

Disclaimer: This is my understanding about this topic read from various official content. Please feel free to correct me if you happen to see mistakes in this post.

 

<Update: 20/1/2016>

ASP.NET 5 is now renamed as ASP.NET Core 1.0

http://www.hanselman.com/blog/ASPNET5IsDeadIntroducingASPNETCore10AndNETCore10.aspx 

</Update>

2015-12-04 Posted by | Uncategorized | , , , , , | Leave a comment

How to automate your Azure Infra tasks using Azure Automation?

We always wanted to shut down our VM’s when not in use so that we can save our subscription bill amount. But many times, we forget to stop it resulting $0 credit 😦 like me below. clip_image001

 

 

 

 

This not only affects our ongoing cloud developments but affects our important hosted apps in production. Yes, recently I published an Office Add in/Apps to the store(production) which is not available now. At present, we do not have an option to allot or block certain amount of credit towards an app so that such critical production would continue.. Any one aware of blocking the credits to different offerings?

Side note : Just learned from here –> Amazon EC2 instances are billed by the “hour” as opposed to by the “minute” with Azure.

Let us talk about how we can automate certain Azure infra tasks like auto shutdown or deallocate after testing using Azure Automation. This blog post is based on our PFE blog but wanted to try first-hand experience to start as blog. I encourage you to try at your phase, so that it gives good idea exploring various options and possibilities with PowerShell. Most importantly. you can reuse the same automation for your real time resource management down the line. Ok, let’s start.

Microsoft Azure Automation

provides a way to automate a simple <-> complex manual infra tasks, often repeated or could be a long running, error-prone activities performed by devops(mostly) during testing/deployment can be easily be automated using scripting (PowerShell). You can reuse the same script for DEV, TESTING, STAGING and PROD environment easily for similar replication/setup. Let me break down in points for easy understanding..

  • It also help us to create, supervise, manage and deploy resources to azure using runbooks (Windows PowerShell workflows)
  • You can schedule it for Day/Monthly/yearly so that it can trigger and run the jobs as scripted. It’s kind of a scheduler for managing Azure resources.
  • The runbooks contains the PowerShell works easily with resources like Azure Websites, VM’s, Storage, SQL Server, and other popular Azure services using command lets.
  • Another good candidate, we can also manage windows updates, auto backups/recovery, copy files to storage, prepare machines for deployment etc..
  • Best part is, one can see the job status and result in the portal. It also gives the nicer dashboard displaying failed request, queued jobs and stopped etc.

Note : For this hands-on, you should have a valid azure subscription. If you have got MSDN account, then you could activate it under MSDN subscription page as below or try this link for free trial – https://azure.microsoft.com/en-us/pricing/free-trial/

clip_image002

Microsoft Azure Automation – Overall execution

clip_image003

Let us see it in action:

1) How to start the Automation from Azure old portal or management portal – http://manage.windowsazure.com/

clip_image004

2) Same thing you can try it from Preview Portal also, but we are going to see how to use the management portal for the rest of the hands on –

clip_image005

3) After creating the Automation a/c from the Step1, now click on Assets > Add Settings for adding the credential passed as known value.

clip_image006

clip_image007

4) Enter the credential of the co-admin account. For creating Co-Administrator, please refer here – Azure Automation: Authenticating to Azure using Azure Active Directory http://azure.microsoft.com/en-us/blog/azure-automation-authenticating-to-azure-using-azure-active-directory/

clip_image008

5) Now, let us go ahead and add the Runbook as below.

clip_image009

6) Now, you would get the default workflow as below. Go ahead and copy the below PowerShell script. Make sure, our workflow name and our runbook name should be same. This is very important. Right now we are going to create runbook for Starting our VM’s.

clip_image010

workflow start-my-sharepoint2016-testing {

$cred = Get-AutomationPSCredential -Name “Azure-Automation-Cred”

Add-AzureAccount -Credential $cred

Start-AzureVM -ServiceName “sharepoint216” -Name “sharepoint2016”

}

7) Now save the changes and publish it, so that you can do the scheduling.

clip_image011

clip_image012

clip_image013

8) Let us test by executing it manually..clip_image014

clip_image015

clip_image016

9) Now, I see the VM has started, similarly you can do it for stopping the VM at your scheduled time.

clip_image017

For stopping VM,

workflow Stop-VM-Testing {

$cred = Get-AutomationPSCredential -Name “Azure-Automation-Cred”

Add-AzureAccount -Credential $cred

Stop-AzureVM -ServiceName “sharepoint216” -Name “sharepoint2016” -force

}

I suggest this free ebook from MVA for further detailed documentation about its possibilities and advanced reading :  http://www.microsoftvirtualacademy.com/ebooks#9780735698154 

clip_image018

Starter links:

 

See you next time with some other interesting stuff..

//Happy reading.

2015-09-12 Posted by | Uncategorized | , , , | Leave a comment

   

%d bloggers like this: