Windows Server How-To
How To Work with PowerShell in Linux
Is it possible to remotely monitor with PowerShell installed on a Linux machine?
Ever since Microsoft announced that PowerShell would be made open source, I have been really curious about what it would be like to run PowerShell on a Linux machine. Would it be like managing a Windows server, or would the experience be completely foreign? Eventually, curiosity got the better of me, and I decided to find out. In a recent column, I showed you how to deploy PowerShell on a Linux machine. You can reference that article if you need some help with getting PowerShell up and running. In this column, I want to talk about my experiences with using PowerShell on Linux.
In a Windows environment, PowerShell exists primarily as a tool for managing remote systems. Sure, you can manage the local system and you can even build full-blown applications on PowerShell, but remote management seems to be PowerShell's main purpose. As such, I decided to see if I could remotely manage a Linux machine from Windows.
The first thing that I needed was the Linux machine's IP address. In a Windows environment, I usually get the IP address by using the IPConfig command, but that didn't work in Linux. Of course IPConfig is a leftover from the Windows Command Prompt. The "PowerShell way of doing things" is to use the Get-NetIPAddress cmdlet. Unfortunately, that didn't work either. You can see the results in Figure 1.
Since these common PowerShell cmdlets do not seem to work on a Linux machine, I decided to try something a bit more basic. I decided to check and see if the Get-Command cmdlet would work. Since that command did work, I tried typing Get-Command Get-* This returns a list of all of the PowerShell cmdlets that use the Get verb.
On a Windows machine this command returns hundreds of commands. If you look at Figure 2, for instance, you can see a small fraction of the available commands. In contrast, Linux includes a mere 42 commands and 24 functions that use the Get verb. You can see the difference in Figure 3.
Accepting the idea that Linux does not yet support anywhere near as many PowerShell cmdlets as Windows, I still wanted to see if I could establish a remote PowerShell session. I couldn't use the Get-NetIPAddress cmdlet, and the Enable-PSRemoting cmdlet didn't work either. That being the case, I decided to exit out of PowerShell and use a Linux command to retrieve the machine's IP address. That command is:
Unfortunately, when I tried to use the Enter-PSSession cmdlet, I received a message stating that the WinRM client could not process the request. The error went on to state that if the authentication scheme is different from Kerberos or if the client computer is not domain joined, then HTTPS must be used or the client computer must be added to the trusted hosts configuration settings.
Since using Windows to establish a remote PowerShell session with a Linux machine clearly was not going to work, I decided to try the opposite and see if I could use Linux to establish a remote PowerShell session with a Windows machine. I was initially encouraged because cmdlets such as Get-PSSession and Enter-PSSession actually exist within Linux PowerShell. However, attempting a connection to a Windows machine resulted in a core dump (which is kind of like a blue screen error). You can see the results in Figure 4.
Ultimately, it seems that Microsoft still has a lot of work to do on PowerShell for Linux. Of course, it is unfair for me to judge PowerShell for Linux too harshly, because it is currently an alpha release. There are bound to be bugs and missing features.
For right now, I have found that PowerShell can be used for some basic management tasks on the Linux side of things. For example, the Get-Process cmdlet works in Linux, as does Get-ChildItem. I am confident that over time, PowerShell for Linux will become more powerful and useful. I am also relatively sure that Microsoft will eventually make cross-platform PowerShell remoting work. As it stands right now, PowerShell for Linux is more of a preview release that is intended for learning purposes than a full-blown management shell.
Brien Posey is a seven time Microsoft MVP with over two decades of IT experience. As a freelance writer, Posey has written many thousands of articles and written or contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and healthcare facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. When He isn't busy writing, Brien Posey enjoys exotic travel, scuba diving, and racing his Cigarette boat. You can visit his personal Web site at: www.brienposey.com.