Platform independence with PowerShell Core

Beyond the Horizon


Microsoft introduced a command type in PowerShell that is still a nuisance for many Windows PowerShell aficionados today. Windows administrators used graphical tools far more often than the command line, and Windows Script Host. To make the transition to the new tool easier, commands from CMD and Bash were adapted, but with special features. For example, a call only redirects to the get-ChildItem cmdlet. The use of switches, as in dir /a /p, is not possible, because only the command name is implemented as an alias for get-ChildItem, not its control options.

However, the biggest disadvantage of using an alias becomes apparent in the context of the other PowerShell command types. The PowerShell interactive console allows you to use binaries, scripts, functions, cmdlets, and aliases directly. If command names now exist in two or more command types, a certain sequence results during processing. The alias would be executed first, then the function, and then cmdlet scripts and executables. An ls alias would overwrite the Unix ls standard command, and the same applies to the ps command. For this reason, dropping these (and other) aliases makes sense.

PSCore under Linux has other special features:

  • As with Windows, the shell is not case sensitive for constructs and variables.
  • Only the elements derived from the providers FileSystem, Variable, Alias, and Function exist as PowerShell drives.
  • Paths must be separated with a slash (/).

Reasons for PowerShell on Linux

Linux administrators have a good selection of tools like Grep, Awk, and Bash, but there are good reasons to draw attention to PSCore under Linux, as well. Since Desired State Configuration and the development of special Linux management resources, Microsoft has consistently followed the path of cross-platform management, because the standardization of concepts and tools creates more consistent environments.

The strength of Linux lies in the combination of the Bash and PSCore pipeline. The following example, for example, stops all processes with a working set larger than 5MB:

> Get-Process | Where-Object -FilterScript { $_.WS -gt 5MB } | Stop-Process

The native solution on Linux would be a complex combination of Bash, AWK, and Grep. The PowerShell's very good input and output possibilities are likely to inspire many Linux adminstrators. PSCore can natively handle HTML, JSON, CSV, and XML formats, which is a qualitative benefit, especially for reporting scripts:

> Get-Content /etc/passwd | ConvertFrom-Csv -Delimiter ':' -Header Name,Passwd,UID,GID, Description,Home,Shell | Sort-Object Name | convertto-html | Out-File /home/thomas/passwd.html

The output of this command generates a tabular report.

Remote Access, Old and New

In PowerShell versions 2 to 5, remote access is implemented with the WS-Management Protocol. PowerShell endpoints on the devices communicate by HTTP listeners. The endpoints can vary and be configured individually. The output of Get-PsSessionConfiguration provides a first clue.

Alternatively, you can now use SSH for remote maintenance in PowerShell 6. Instead of authentication by AD or entries in the list of trusted hosts in the WinRM configuration, a user account and password can be passed during connection. This approach is made possible by the new SshTransport parameter, which has been reassigned to the commands New-PsSession, Enter-PsSession, and Invoke-Command. When called, you can pass in a username on the target system; the password is then queried interactively. SSH servers and clients are available for Windows (e.g., CopSSH [2]).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs

Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>


		<div class=