Tag: remote

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.



PowerShell Direct Enter-PSSession

Hyper-V PowerShell Direct

One of the new features of Hyper-V in Windows Server 2016 and Windows 10 is called PowerShell Direct. PowerShell Direct lets you remotely connect to a Virtual Machine running on a Hyper-V host, without any network connection inside the Virtual Machine. PowerShell Direct uses the Hyper-V VMBus to connect inside the Virtual Machine. This feature is really handy if you need it for automation and configuration for Virtual Machines or if you for example messed up network configuration inside the virtual machine and you don’t have console access.

Right now there are two ways to use PowerShell Direct:

  • Create and exit a PowerShell Direct session using PSSession cmdlets
  • Run script or command with the Invoke-Command cmdlet
  • Use the PowerShell Direct session to copy files using the copy-item cmdlet

Requirements:

  • The virtual machine must be running locally on the Hyper-V host and must be started.
  • You must be logged into the host computer as a Hyper-V administrator.
  • You must supply valid user credentials for the virtual machine.
  • The host operating system must run Windows 10, Windows Server 2016, or a higher version.
  • The virtual machine must run Windows 10, Windows Server 2016, or a higher version.

PowerShell Direct examples

You can open a new interactive PowerShell Direct Session:

PowerShell Direct Enter-PSSession

Enter-PSSession -VMName "VM01" -Credential (Get-Credential)

PowerShell Direct Invoke-Command

You can use Invoke-Command to send script blocks to your Hyper-V Virtual Machines.

Invoke-Command -VMName "VM01" -Credential (Get-Credential) -ScriptBlock { Get-Process }

You can also create a PowerShell Direct session and use the Copy-Item -ToSession cmdlet to copy files to or from the VM.

$s = New-PSSession -VMName "VM01" -Credential (Get-Credential)
Copy-Item C:\Files C:\Targetfiles -ToSession $s

Remember it, this is not the same as PowerShell Remoting, even if it uses the same cmdlets. With that, not everything is working using PowerShell Direct, for some scenarios PowerShell Remoting works differently. If you want to do this with Linux virtual machines, there is a tool called hvc.exe, which allows you to do the same.

If you want to know more about PowerShell Direct, check out the Microsoft Docs pages.



Microsoft Remote Desktop Preview App

Microsoft Remote Desktop Preview App for Windows 10

Yesterday Microsoft announced a new Remote Desktop Preview app for Windows 10 Universal Windows Platform (UWP) on the Remote Desktop Services Blog. You can get and download from the Windows Store. The new Remote Desktop Preview app has a connection center to manage your connections to Windows Clients and Windows Server. The connection center is your starting point. It allows you to easily manage your desktops. You can add new desktop connections and edit or delete existing connections. Selecting one of the desktop tiles launches the connection. It’s great to see Microsoft finally creating some great Apps for their own Universal Windows Platform.

Microsoft Remote Desktop Preview App Connection Center



Windows Intune July 2011 Beta

Windows Intune Logo

Microsoft released the July 2011 Beta of Windows Intune yesterday. The new beta brings a lot of new cool features which were missing in the first version of Windows Intune.

  • Software Distribution
  • License Management for third-party software
  • Enhanced Reporting
  • Read-only Access Administrators
  • Offline Client Installation
  • Remote Tasks (Malware scan etc)
  • and more…

If you need more information on the July beta of Windows Intune you can download the Factsheet or get more information on technet.

I think through this update Windows Intune gets the features it needs to be successful. This is a great opportunity for small and mid-sized which not had a Software Distribution in place, to get an easy solution.



Run Remote Powershell Commands on multiple standalone Computers

Powershell Header

With this little Powershell Script you can run Powershell Commands on multiple Remotehosts even if those are not in an Active Directory.

# Config
$Servers = @("Server01", Server02)
$Cred = Get-Credential # Add Credentials for all Servers (Domain or non-Domain)
 
# Run Command (for example Get-Service | Where-Object {$_.Name -eq "BITS"}
foreach ($Server in $Servers) {
	Invoke-Command -ComputerName $Server -Credential $Cred {Get-Service | Where-Object {$_.Name -eq "BITS"}}
}

Important:

You have to enable Powershell Remoting on the Remotehost with Enable-PSRemoting



Quick Powershell Remoting Guide

Powershell HeaderThis is small guide which allows you to create Remote Powershell Sessions (like SSH). It allows you to create connection to Host which have Powershell Version 2.

  • Allow Powershell Remoting on the Remotehost
  • Add Trusted Hosts on the Localcomputer
  • Create a new Remotesession
  • Leave a Powershell Remotesession
  • Close a Powershell Remotesession
  • Send a command to a Remotehost

Allow Powershell Remoting on the Remotehost

Run Powershell 2.0 on the Remotehost and run the following Cmdlet.

Enable-PSRemoting

This command starts the WinRM service if it’s not allready started and sets the startup type to automatic. Adds firewall exceptions for WS-Management communications and creates a listener to accept requests.

Add Trusted Hosts on the Localcomputer

On the Local Computer run Powershell and run the following Cmdlet. This allows you to connect to any host. It also starts WinRM if its not already started.

Set-Item WSMan:\localhost\Client\TrustedHosts *

After that you may have to restart the WinRM service

Restart-Service winrm -Force

Create a new Powershell Remotesession

There are two ways to create a new PS Remotesession.

New-PSSession -ComputerName Server01

With Get-PSSession you can list all active sessions. Now you can enter a active Session with Enter-PSSession and the ID

Enter-PSSession 2

A quicker way to do that, you can simply use Enter-PSSession to create a new Session and directly connect to this Session.

Enter-PSSession -ComputerName Server02

Leave a Powershell Remotesession

To leave a Powershell Remotesession you can simply use the Exit-PSSession

Exit-PSSession

Close a Powershell Remotesession

To close a Powershell Remotesession you can list all  active Sessions with Get-PSSessions and close them with Remove-PSSession.

Get-PSSession | Remove-PSSession

Send a command to a Remotehost

To run a command on a Remotehost you can use the -ComputerName parameter.

Get-Service -ComputerName Server02
Get-Service -ComputerName Server02 | Where-Object {$_.Name -eq "BITS"}

With this little snippet you can run commands on multiple Hosts

 
$Servers = @("Server01", "Server02")
 
foreach ($Server in $Servers) {
 
Write-Host "Server: " $server
 
Get-Service -ComputerName $server | Where-Object {$_.Name -eq "BITS"}
 
}


Still love my iPad

iPad

I still love my iPad. Now I really start to work with it. It keeps my life simple and easy.

First I start with a daily briefing with my todos (Things) and events for today. I also read a lot of news with my Google Reader app (Newsrack) which also syncs with my iPhone, so I always see whats new around the tech world.

Through the day I need it to get quick information about tech or other stuff. I also use it for social networks like facebook, twitter and so on.

iPad iTap RDP

With Apps like iTap RDP I can use it to control Windows Server in our Datacenter and create and read notes with Evernote. There is also a pretty cool Powershell Guide for the iPhone and the iPad called iPowershell.

iPadAt home I use it as a Remote Controller for iTunes, my Dreambox and other things. And if I have a moment i don’t need it, I use it as a Picture frame.

Important to note, the iPad does not replace my notebook or my iPhone, but there are a lot of new things, I never thought about I could do this way.