Tag: Visual Studio Code

Visual Studio Code Azure Virtual Machines Extension

Create and Manage Azure VMs from VS Code

With the new Azure Virtual Machines (VMs) extension for Visual Studio Code (VS Code), you can now create and manage Azure VMs directly from VS Code. This is a great new extension if you are working with VS Code and Microsoft Azure. The extension is currently in preview and lets you view, create, delete, start and stop Azure Virtual machines, as well as adding SSH keys to existing Azure VMs.

Get started

To get started with the Azure Virtual Machine extension in Visual Studio Code, simply follow these steps:

  1. Download and install the Azure Virtual Machines extension for Visual Studio Code
  2. Once complete, you’ll see an Azure icon in the Activity Bar
  3. Sign in to your Azure account by clicking Sign in to Azure. If you don’t have an Azure account yet, you can create a free Azure account here.

Free Azure Account

If you don’t have an Azure account yet, you can sign up today for your free Azure account and receive 12 months of free popular services, $200 free credit, and 25+ always free services.

Create an Azure VM in VS Code

You can now create Azure VMs directly from Visual Studio Code. The wizard will ask you for a VM name, username, Azure region, and passphrase.

VS Code creating Azure Virtual Machines

VS Code creating Azure Virtual Machines

This will create an Azure VM Standard D2s V3 (2 CPU Cores & 8 GB of ram) with the image Ubuntu 18.04-LTS. An SSH key will be created, and your SSH Config file (~/.ssh/config) will be updated so you can immediately connect via SSH ($ ssh vm-name) or using the Remote-SSH extension. You can find more information about how you can connect to Azure VM using Visual Studio Code in my blog post.

Azure VM management in VS Code

Azure VM management in VS Code

Having the possibility to manage Azure VMs and connect with them directly within Visual Studio makes working with these tools and Azure much more convenient.

I hope you can go and try out the Azure VM extension for VS Code. If you have any questions, please feel free to leave a comment.



PowerShell ISE Mode in Visual Studio Code

How to use PowerShell ISE Mode in Visual Studio Code

If you are writing PowerShell code, you might have realized that there weren’t really improvements to the PowerShell Integrated Scripting Environment (PowerShell ISE) in the last couple of releases. With PowerShell becoming more popular on cross-platform systems, Visual Studio Code (VS Code) becomes the editor of choice. However, by default Visual Studio Code has a different behavior than the PowerShell ISE. To make it even easier, the latest PowerShell extension for Visual Studio Code, now includes PowerShell ISE Mode. PowerShell ISE Mode in Visual Studio Code, helps you to replicate and enable the settings from the following Microsoft Docs article: How to replicate the ISE experience in Visual Studio Code.

The ISE was first introduced with Windows PowerShell V2 and was re-designed with PowerShell V3. The ISE is supported in all supported versions of Windows PowerShell up to and including Windows PowerShell V5.1.

The PowerShell ISE is no longer in active feature development. As a shipping component of Windows, it continues to be officially supported for security and high-priority servicing fixes. We currently have no plans to remove the ISE from Windows.

There is no support for the ISE in PowerShell v6 and beyond.



Cascadia Code in Windows Terminal

New Microsoft Code and Terminal Font Cascadia Code

Cascadia Code is the latest monospaced font shipped from Microsoft focusing on delivering an excellent font for command-line experiences and code editors like Visual Studio Code. The Cascadia Code font was first announced at the Microsoft Build conference in May 2019. And yesterday, Microsoft just released Cascadia Code version 1909.16 and it is available publicly on GitHub. Cascadia Code makes an excellent font for the Windows Terminal, and you can download it today.

It is the latest monospaced font shipped from Microsoft and provides a fresh experience for command line experiences and code editors. Cascadia Code was developed hand-in-hand with the new Windows Terminal application. This font is most recommended to be used with terminal applications and text editors such as Visual Studio and Visual Studio Code.

I took some time to install Cascadia Code font on my Surface Book 2 and it works great with application like Visual Studio Code and the Windows Terminal running PowerShell. To start using it, simply download the font, install it, and configure the application to use is. In the Windows Terminal app, open the settings.json file and change the font in the specific terminal profile.

VS Code Cascadia Code setting for Windows Terminal

VS Code Cascadia Code setting for Windows Terminal

  "profiles" : 
    [
        {
            "acrylicOpacity" : 0.5,
            "closeOnExit" : true,
            "colorScheme" : "VibrantInk",
            "commandline" : "C:\\Program Files\\PowerShell\\6\\pwsh.exe",
            "cursorColor" : "#FFFFFF",
            "cursorShape" : "bar",
            "fontFace" : "Cascadia Code",
            "fontSize" : 12,
            "guid" : "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
            "historySize" : 9001,
            "icon" : "ms-appx:///ProfileIcons/{574e775e-4f2a-5b96-ac1e-a2962a402336}.png",
            "name" : "PowerShell Core",
            "padding" : "0, 0, 0, 0",
            "snapOnInput" : true,
            "startingDirectory" : "%USERPROFILE%",
            "useAcrylic" : true,
            "backgroundImage": "C:/Users/thoma/OneDrive/Pictures/Me/Thomas Maurer Logos 2016/WindowsTerminal/Black Cloud Robot.png",
            "tabTitle": "PowerShell Core "
        },

If you want to know more about customizing the Windows Terminal, check out my blog post. You can find more tips on how to customize the Windows Terminal on my blog. If you are optimizing and customizing your code editor experience, you should also have a look at my favorite themes for Visual Studio Code.

The font is open source and licensed under the SIL Open Font license on GitHub, so it is easy to contribute. Have you tried the Cascadia Code font, and what do you think about the new coding font? Do you like it? And if you have any questions, please let me know in the comments.

If you are looking for some other cool Microsoft coding projects, have a look at Azure Cloud Shell and PowerShell 7.



SSH Remote Edit File with Visual Studio Code

Remote Edit Files on Azure Linux VMs using VS Code

There are a lot of different ways to remote manage your Azure virtual machines using various tools and technics. In this blog post, I am going to show you how you can remotely edit files on Azure Linux virtual machines using Visual Studio Code. Visual Studio Code has a new Remote Development Extention which allows you to open any folder in a container, on a remote computer, or in the Windows Subsystem for Linux (WSL) and take advantage of the VS Code feature set. With the Remote – SSH extensions, you can easily browse and edit files on an Azure VM or any other system where you can connect using SSH.

Installation

As mentioned to edit the files on the Azure Linux virtual machine remotely, we are using the light-weight, cross-platform, opensource editor Visual Studio Code. You can download and install VS Code from the official website.

Visual Studio Code Remote Development Extension

In addition to Visual Studio code, we need to install the Remote – SSH extension, which comes with Remote Development Extension Pack. This also includes remote extensions for containers or the Windows Subsystem for Linux (WSL).

If you are running on a Windows 10 machine, you will also need to install the OpenSSH client on your machine. You can do that going through this blog post, or by running this command.

# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

Azure VM connection using SSH

The Remote – SSH extensions currently only supports connecting to x86_64 Linux-based SSH servers using key-based authentication.

Optional: Create Azure Linux VM with key-based SSH authentication using the Azure CLI

Create Azure Linux VM Azure CLI SSH Keys DNS Name

If you want to try it out, and you haven’t set up a Linux VM SSH and key-based authentication. This Azure CLI command here helps you to create a new Azure virtual machine and sets up ssh keys as well as an optional unique Azure DNS name.

az vm create --resource-group demosshvm --name tomsVM --image UbuntuLTS --admin-username thomas --generate-ssh-keys --public-ip-address-dns-name tomsazurelinuxvm

In this example, you can use the public IP address or the Azure FQDN to connect to the Azure VM. If you have a VPN or Express Route set up, you can also use private IP addresses and DNS names. If you are using public IP addresses in production, make sure you are using a service like Azure Just in Time VM access.

Connect Visual Studio Code to Azure VM using SSH

After you have installed Visual Studio Code, the Remote – SSH extension, the SSH client and have a VM with key-based authentication, you can now easily connect. Open Visual Studio Code, on the bottom left, you see the Remote connection button. If you press it, you will find the remoting options. Select “Remote-SSH: Connect to Host…

Visual Studio Open Remote SSH Connection

This will ask you for the username and IP address or DNS name of the virtual machine. In my case, I am going to use the DNS name.

Visual Studio Code SSH Remoting Connection

 

After pressing enter, this will connect your Visual Studio Code environment to the Azure virtual machine.

Visual Studio Code SSH Connection

 

Remote edit files on Azure Linux VMs using VS Code

You can start opening folders and files on the remote Azure Linux VM and begin browsing the file system. On the bottom left, you see the name or IP address of the machine you are connected with.

SSH Remote File System Visual Studio Code

You can also open files and start remote edit files on your Azure Linux VM. If you save the changes you made to the file, this is directly saved on the remote Azure virtual machine.

SSH Remote Edit File with Visual Studio Code

You get all the advanced VS Code features you know from your local Visual Studio Code like syntax-highlighting and more.

I hope this shows you an easy way to remotely edit files on your Azure Linux virtual machines using Visual Studio Code and SSH. If you have any questions, please let me know in the comments.



Mastering Azure with Cloud Shell

Mastering Azure with Cloud Shell

There are multiple ways to interact and manage resources in Microsoft Azure. You can use the Azure Portal or command line tools like the Azure PowerShell module or the Azure CLI, which you can install on your local machine. However, to set up a cloud management workstation for administrators and developers can be quite a lot of work. Especially if you have multiple computers, keeping consistency between these machines can be challenging. Another challenge is keeping the environment secure and all the tools up to date. The Azure Cloud Shell addresses this any many more things.

Cloud Shell is not brand new, Microsoft announced Cloud Shell at Build 2017. This blog post is about how you can master Azure with Cloud Shell and give you an overview of the possibilities of Cloud Shell.

 

What is Cloud Shell

Cloud Shell Azure Portal

Cloud Shell offers a browser-accessible, pre-configured shell experience for managing Azure resources without the overhead of installing, versioning, and maintaining a machine yourself. Azure Cloud Shell is assigned per unique user account and automatically authenticated with each session. This makes it a private and secure environment.

You get a modern web-based command line experience which can be accessed from several endpoints like the Azure Portal, shell.azure.com and the Azure mobile app, Visual Studio Code or directly in the Azure docs.

In the backend, Azure uses containers and automatically attaches an Azure File Share to the container. You can store the data on it, so your data is persistent. This persists your data across different Cloud Shell sessions.

Cloud Shell Bash and PowerShell

You can choose your preferred shell experience. Cloud Shell supports Bash and PowerShell and included your favorite third-party tools and standard tools and languages. If something like a module is missing, you can add it.



VSCode in Azure Cloud Shell

You can now run a Visual Studio Code based editor in Azure Cloud Shell

Azure Cloud Shell, a browser-accessible shell for managing Azure resources, just got even more powerful. Today Microsoft added a new Visual Studio Code editor to Azure Cloud Shell. Okay, it is not the real Visual Studio Code, it is an editor based on the Visual Studio Code open-source project Monaco. Monaco is the same web-standards based editor that powers Visual Studio Code, and the editor is now integrated directly into Cloud Shell.

Now you not only have editors like vim, emacs or nano, you also able to run code, directly with in the Azure Cloud Shell. This is pretty handy when it comes to quickly edit some files like scripts or ARM templates.

This is not the first time the Azure Cloud Shell team and the Visual Studio Code team collaborated: Azure Cloud Shell in Visual Studio Code



Azure Stack Tools

Set up an Azure Stack Cloud Operator and Developer Workstation Environment

If you are responsible for managing and operating Azure Stack, you will need to enable a couple of tools to manage Azure Stack. This post should give you a summary of what you should do to setup your Azure Stack Operator and Developer workstation environment.

Operating System

Azure Stack Windows Admin Workstation

First of all, you should set up a clean base system. I usually use the latest version of Windows 10, right now the latest Windows 10 version is the Fall Creators Update which gives you some great features like the OpenSSH client or the Windows Subsystem for Linux build in, or I use Windows Server 2016 with Desktop Experience. Make sure you install all the latest updates for Microsoft Update.

Install Visual Studio Code

PowerShell for Visual Studio Code

Visual Studio Code is a new, free, lightweight cross-platform code editor for building modern web and cloud applications on Mac OS X, Linux, and Windows. It is perfect for editing JSON files and even writing some code. And it has a built-in Terminal, so you don’t have to switch between different windows.

I recommend you install the following Extensions:

code --install-extension ms-vscode.vscode-azureextensionpack
code --install-extension ms-vscode.powershell
 
code --list-extensions

Install SSH Client or Windows Subsystem for Linux (WSL)

OpenSSH Windows 10

To manage if you need to manage the hardware switches, border switches, Linux Virtual Machines running on Azure Stack is connected, SSH is the way to access it. Windows 10 now comes with several builtin options like the OpenSSH Client which you can install as an additional feature or for example the Windows Subsystem for Linux (WSL) which allows you to run several Linux tools on Windows directly. If you are using another version of Windows, the third-party application PuTTY is your friend.

You can also use PowerShell to install it:

Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
 
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
 
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

Install Azure Stack PowerShell

Install Azure Stack PowerShell

Azure Stack compatible Azure PowerShell modules are required to work with Azure Stack. PowerShell commands for Azure Stack are installed through the PowerShell gallery. You can run the following commands to install it (Make sure there are no other Azure PowerShell Modules installed, if there are, the commands will remove them). If you also install Visual Studio, install Visual Studio first before you install the Azure Stack PowerShell.

# Trust the PowerShell Gallery
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
 
# Remove Existing Azure PowerShell Modules
Get-Module -ListAvailable | where-Object {$_.Name -like “Azure*} | Uninstall-Module
 
# Install the AzureRM.Bootstrapper module. Select Yes when prompted to install NuGet
Install-Module -Name AzureRm.BootStrapper
 
# Install and import the API Version Profile required by Azure Stack into the current PowerShell session.
Use-AzureRmProfile -Profile 2017-03-09-profile -Force
 
#Install Azure Stack Module
Install-Module -Name AzureStack -RequiredVersion 1.2.11
 
# Verify Installation
Get-Module -ListAvailable | where-Object {$_.Name -like "Azure*"}

If you need to install it on a machine which does not have access to the internet. check out the official Microsoft page: Install PowerShell for Azure Stack

Install Azure Stack tools

Azure Stack Tools

AzureStack-Tools is a GitHub repository that hosts PowerShell modules that you can use to manage and deploy resources to Azure Stack. This brings you several functionalities for Azure Stack management:

  • Deployment of Azure Stack – Helps prepare for Azure Stack deployment.
  • Resource Manager policy for Azure Stack – Constrains Azure subscription to the capabilities available in the Azure Stack.
  • Connecting to Azure Stack – Connect to an Azure Stack instance from your personal computer/laptop.
  • Setting up Identity for Azure Stack – Create and manage identity-related objects and configurations for Azure Stack
  • Azure Stack Service Administration – Manage plans and subscriptions in Azure Stack.
  • Azure Stack Compute Administration – Manage compute (VM) service in Azure Stack.
  • AzureRM Template validator – Validate Azure ARM Template Capabilities
  • Azure Stack Infrastructure Administration – Manage Azure Stack Infrastructure

You can get the Azure Stack tools from GitHub:

# Change directory to the root directory
cd \
 
# Download the tools archive
Invoke-WebRequest https://github.com/Azure/AzureStack-Tools/archive/master.zip -OutFile master.zip
 
# Expand the downloaded files
Expand-Archive master.zip -DestinationPath . -Force
 
# Change to the tools directory
cd AzureStack-Tools-master

You can directly open that folder in Visual Studio Code:

code C:\AzureStack-Tools-master

Configure Azure Stack PowerShell environment

As an Azure Stack user, you can configure your Azure Stack PowerShell environment. After you have configured the environment, you can use PowerShell to manage Azure Stack resources such as subscribe to offers, create virtual machines, deploy Azure Resource Manager templates, etc.

For an Azure Stack deployment which is using Azure Active Directory (AAD) as an Identity Provider, you can use the following commands:

# Navigate to the downloaded folder and import the **Connect** PowerShell module
Set-ExecutionPolicy RemoteSigned
Import-Module .\Connect\AzureStack.Connect.psm1
 
# For Azure Stack development kit, this value is set to https://management.local.azurestack.external. For a real Azure Stack solution this will be https://maangement.-region-.-fqdn-
$ArmEndpoint = "<Resource Manager endpoint for your environment>"
 
# For Azure Stack development kit, this value is set to https://graph.windows.net/.
$GraphAudience = "<GraphAudience endpoint for your environment>"
 
# Register an AzureRM environment that targets your Azure Stack instance
Add-AzureRMEnvironment `
-Name "AzureStackUser" `
-ArmEndpoint $ArmEndpoint
 
# Set the GraphEndpointResourceId value
Set-AzureRmEnvironment `
-Name "AzureStackUser" `
-GraphAudience $GraphAudience
 
# Get the Active Directory tenantId that is used to deploy Azure Stack
$TenantID = Get-AzsDirectoryTenantId `
-AADTenantName "<myDirectoryTenantName>.onmicrosoft.com" `
-EnvironmentName "AzureStackUser"
 
# Sign in to your environment
Login-AzureRmAccount `
-EnvironmentName "AzureStackUser" `
-TenantId $TenantID

Install and configure CLI for use with Azure Stack

Azure CLI

You can also use the Azure CLI 2.0 to manage Azure Stack.

Install Azure CLI on Windows using MSI

To install the CLI on Windows and use it in the Windows command-line, download and run the Azure CLI Installer (MSI).

Install with apt-get for Bash on Ubuntu on Windows (WSL)

  1. Open the Bash shell.
  2. Modify your sources list.
    echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \
    sudo tee /etc/apt/sources.list.d/azure-cli.list
  3. Run the following sudo commands:
    sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 52E16F86FEE04B979B07E28DB02C46DF417A0893
    sudo apt-get install apt-transport-https
    sudo apt-get update && sudo apt-get install azure-cli
  4. Run the CLI from the command prompt with the az command.

Connect to Azure Stack using the Azure CLI

If you are using Public Certificates for your Azure Stack, this is pretty straight forward, if you are using the Azure Stack Development Kit or an Internal CA, make sure your client trusts the Azure Stack CA root Certificate. You can find more here: Install and configure CLI for use with Azure Stack

Register your Azure Stack environment by running the az cloud register command.

Register as a cloud administrative environment:

  1. To register the cloud administrative environment, use:
    az cloud register \
    -n AzureStackAdmin \
    --endpoint-resource-manager "https://adminmanagement.-region-.FQDN-" \
    --suffix-storage-endpoint "-region-.FQDN-" \
    --suffix-keyvault-dns ".adminvault.-region-.FQDN-" \
    --endpoint-active-directory-graph-resource-id "https://graph.windows.net/" \
    --endpoint-vm-image-alias-doc <URI of the document which contains virtual machine image aliases>
  2. Set the active environment by using the following commands.
    az cloud set \
    -n AzureStackAdmin
  3. Update your environment configuration to use the Azure Stack specific API version profile. To update the configuration, run the following command:
    az cloud update \
    --profile 2017-03-09-profile
  4. Sign in to your Azure Stack environment by using the az login command. You can sign in to the Azure Stack environment either as a user or as a service principal.
    az login \
    -u <Active directory global administrator or user account. For example: username@<aadtenant>.onmicrosoft.com> \
    --tenant <Azure Active Directory Tenant name. For example: myazurestack.onmicrosoft.com>

Register the user environment, use:

  1. To register the user environment, use:
    az cloud register \
    -n AzureStackUser \
    --endpoint-resource-manager "https://management.local.azurestack.external" \
    --suffix-storage-endpoint "local.azurestack.external" \
    --suffix-keyvault-dns ".vault.local.azurestack.external" \
    --endpoint-active-directory-graph-resource-id "https://graph.windows.net/" \
    --endpoint-vm-image-alias-doc <URI of the document which contains virtual machine image aliases>
  2. Set the active environment by using the following commands.
    az cloud set \
    -n AzureStackUser
  3. Update your environment configuration to use the Azure Stack specific API version profile. To update the configuration, run the following command:
    az cloud update \
    --profile 2017-03-09-profile
  4. Sign in to your Azure Stack environment by using the az login command. You can sign in to the Azure Stack environment either as a user or as a service principal.
    az login \
    -u <Active directory global administrator or user account. For example: username@<aadtenant>.onmicrosoft.com> \
    --tenant <Azure Active Directory Tenant name. For example: myazurestack.onmicrosoft.com>

Install the Microsoft Azure Storage Explorer

Azure Stack Azure Storage Explorer

To access and manage Azure Stack Storage Accounts, you can also use the Microsoft Azure Storage Explorer tool. Microsoft Azure Storage Explorer (Preview) is a standalone app from Microsoft that allows you to quickly work with Azure Storage data on Windows, macOS, and Linux.

If you are running the Azure Stack Development Kit, you should again have a look at how you get the certificates in place, and you can find that here: Connect Storage Explorer to an Azure Stack subscription

  1. Install the Microsoft Azure Storage Explorer
  2. After Storage Explorer restarts, select the Edit menu, and then ensure that Target Azure Stack is selected. If it is not selected, select it, and then restart Storage Explorer for the change to take effect. This configuration is required for compatibility with your Azure Stack environment.
  3. To connect to the Azure Stack account, select Add an account.
  4. In the Connect to Azure Storage dialog box, under Azure environment, select Use Azure Stack Environment, and then click Next.
  5. To sign in with the Azure Stack account that’s associated with at least one active Azure Stack subscription, fill in the Sign in to Azure Stack Environment dialog box.
    The details for each field are as follows: Environment name: The field can be customized by the user.
    ARM resource endpoint: The samples of Azure Resource Manager resource endpoints: For cloud operator:
    https://adminmanagement.-region-.-FQDN-
    For tenant:
    https://management.-region-.-FQDN-
    Tenant Id: Optional. The value is given only when the directory must be specified.

This should help you quickly set up an Azure Stack Cloud Operator Workstation. What other tools do you need to manage and operator your Azure Stack? Leave a comment.

If you want to know more about the responsibilities and toolset of an Azure Stack Operator, check out my blog post at the Microsoft IT OpsTalk blog.