Convert Possibilities into Business Value

Post navigation

How to Add a Linux Machine as PowerShell Host in vRO

Introduction

In this article we will look into the alpha version of Microsoft Windows PowerShell v6 for both Linux and Microsoft Windows. We will show how to execute PowerShell commands between Linux , Windows, and VMware vRealize Orchestrator (vRO):

Linux to Windows

Windows to Linux

Linux to Linux

vRO to Linux

We will also show how to add a Linux PowerShell (PSHost) in vRO.

Currently, the alpha version of PowerShell v6 doesnot support the PSCredential object, so we cannot use the Invoke-Command command to programmatically pass credentials and execute commands from vRO, through a Linux PSHost, to other Linux machines, or Windows machines. Conversely, we cannot execute from vRO –> through a Windows PSHost –> to Linux Machines.

In addition to not supporting the PSCredential object, the alpha version doesn’t support WinRM. WinRM is Microsoft’s implementation of the WS-Management protocol, a standard Simple Object Access Protocol (SOAP)-based, firewall-friendly protocol that enables hardware and operating systems from different vendors to interoperate. Therefore, when adding a Linux machine as a PowerShell host in vRO, we will be using SSH instead of WinRM as the protocol of choice.

The PowerShell v6 RTM version is expected to support WinRM, so we will be able to add the Linux PSHost with WinRM, and not SSH.

So, let’s get started.

Installing and Configuring PowerShell 6

Setup on Windows

To install PowerShell v6 (currently in alpha) on a Windows Server 2012 R2, first you need to install the Visual C++ Redistributable 2015 package as a prerequisite.

Note: In some cases you may have to install the entire MicrosoftVisual Studio 2015 product before you are able to install the MicrosoftVisual C++ Redistributable 2015 package.

An installation of PowerShell can establish PowerShell sessions to remote computers using New-PSSession and Enter-PSSession. To enable it to accept incoming PowerShell remote connections, the user must create a WinRM remoting endpoint. This is an explicit opt-in scenario where the user runs Install-PowerShellRemoting.ps1 to create the WinRM endpoint. The installation script is a short-term solution until Microsoft adds additional functionality to Enable-PSRemoting to perform the same action. For more details, see issue #1193, WinRM Plugin Registration and Modification.

Run the above PowerShell script again and this time it should complete successfully.

Now let’s open a PowerShell v6 console.

Note: If you open the usual PowerShell console it will not open a PowerShell v6 console. In my case I already have PowerShell v5 installed. You can check which version of PowerShell you are running in the console by running the following command:

$PSVersionTable.PSVersion.

In my case if I open the usual PowerShell console and run the command I see PowerShell v5:

If you want to open the PowerShell v6 console you can access it from the Windows start menu:

If you receive the following error, you haven’t installed the Visual C++ Redistributable 2015 prerequisite package.

Check the PowerShell version to verify it is the one you need:

If you want to access PowerShell v6 from the default PowerShell console you have to create a new PSSession and use the PowerShell.6.0.0-alpha.9 configuration name:

Open an SSH session to the Linux machine and run the following command to enter into PowerShell:

powershell

Installing and Configuring OpenSSH

PowerShell remoting normally uses WinRM for connection negotiation and data transport. SSH was chosen for this remoting implementation since it is now available for both Linux and Windows platforms, and allows true multiplatform PowerShell remoting. However, WinRM also provides a robust hosting model for PowerShell remote sessions which this implementation does not yet do. And this means that PowerShell remote endpoint configuration and JEA (Just Enough Administration) is not yet supported in this implementation.

PowerShell SSH remoting lets you do basic PowerShell session remoting between Windows and Linux machines. This is done by creating a PowerShell hosting process on the target machine as an SSH subsystem. Eventually this will be changed to a more general hosting model similar to how WinRM works in order to support endpoint configuration and JEA.

The New-PSSession, Enter-PSSession and Invoke-Command cmdlets now have a new parameter set to facilitate this new remoting connection.

[-HostName <string>] [-UserName <string>] [-KeyPath <string>]

This new parameter set will likely change but for now allows you to create SSH PSSessions that you can interact with from the command line or invoke commands and scripts on. You specify the target machine with the HostName parameter and provide the user name with UserName. When running the cmdlets interactively at the PowerShell command line you will be prompted for a password. But you also have the option to use SSH key authentication and provide a private key file path with the KeyPath parameter. Note that PSCredential is not yet supported.

SSH is required to be installed on all machines.

You should install both client (ssh.exe) and server (sshd.exe) so that you can experiment with remoting to and from the machines.

For Windows you will need to install Win32 Open SSH from GitHub.

For Linux you will need to install SSH (including server) appropriate to your platform.

You will also need a recent PowerShell build or package from GitHub having the SSH remoting feature. SSH Subsystems is used to establish a PowerShell process on the remote machine and the SSH server will need to be configured for that.

In addition you will need to enable password authentication and optionally key based authentication.

Linux to Windows

Let’s first test executing a remote command from our Linux to our Windows PowerShell machine. We will run simple Get-Date and hostname commands on the Windows machine. Enter into PowerShell on the Linux machine and run:

Adding Linux as a Linux PowerShell Host in vRO

We will be adding the host as SSH. WinRM will be supported in the initial RTM release of PowerShell v6.

Note: The latest versions of the PowerShell plugin for vRO does not support SSH, so you should take a previous version of the plugin to get that functionality.

Use the following settings:

PowerShell remote host type: SSH

User Name: administrator_account@domain_name

To test the Linux PSHost use the Invoke a PowerShell script workflow and execute the following simple command:

Get-Date; hostname; whoami

Currently the Alpha version of PowerShell v6 does not support the PSCredential object, so we cannot use the Invoke-Command command to programmatically pass credentials and execute commands from vRO, through a Linux PSHost, to other Linux machines or windows Machines.

And conversely, we cannot execute from vRO , through a Windows PSHost, to Linux Machines.

The first RTM version it is also expected to support WinRM so we will be able to add the Linux PSHost with WinRM and not SSH.

Spas Kaloferov is an acting Solutions Architect member of Professional Services Engineering (PSE) for the Software-Defined Datacenter (SDDC) – a part of the Global Technical & Professional Solutions (GTPS) team. Prior to VMware, Kaloferov focused on cloud computing solutions.

One thought on “How to Add a Linux Machine as PowerShell Host in vRO”

Great Article, I have really enjoyed your article. You show how to add a Linux machine as powershell host in vRO. It is really helpful. I have some doubts on this but you have cleared my all the doubts . I have done by the help of your article. Thanks for sharing.