PowerShell – Useful Windows Bash commands to remember

This is for Linux Newbies when working with both Linux Ubuntu 16.04.01 and Windows Bash (which is based on Ubuntu 16.04.1). Please, get use the execute the following commands at least weekly as updates will be available frequently. And, specially before installing the next new release of PowerShell Open Source.

Look for PowerShell Open Source releases at: https://github.com/PowerShell/PowerShell

Follow these steps on a “Clean” Windows 10 Bash subsystem:

1. Run updates available:

$ sudo apt update

2. After the update there might be upgrade available, so list all upgradable components:

$ apt list --upgradable

3. If there’s a list of upgradable components then proceed with the upgrade step:

$ sudo apt upgrade

When installing PowerShell Open Source after a clean Windows Bash installation. Follow the Github instructions as the installation will end in errors. You must run the following command:

$ sudo apt-get install -f

But still, if it ends in error, try again the following commands on order:

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install -f

You’ll notice the error will be cleared.

Also, be patience when e executing ‘sudo apt upgrade’ as this command will take a little time to complete.

One important thing, pay close attention the either Linux and Windows Bash messages when executing these commands as they will give valuable information. These messages will provide the hint on what to do in case of errors.

Running PowerShell Open Source

Now you can proceed to run powershell from Windows Bash. But it’s not there yet, you’ll still experience the screen issues when executing commands. This has been already noted in Github and they are still working on it.

So, the workaround still applies: http://www.maxtblog.com/2016/10/running-powershell-in-windows-10-bash-workaround/

For a quick console test, try using ‘screen‘ but need to run as ‘root’ privilege :

$ sudo screen

Here are some remediation to caveats with PowerShell when using ‘screen‘.

Important shortcut keys to remember:

2. Use CRTL-L – to CLEAR the screen.

Also, caution, if you run any Linux command from PowerShell it will not terminate and you’ll need to close your session.

The workaround is the save the results of the Linux command to a PowerShell variable and the display the result.

For example, run in PowerShell prompt:

PS c:\Windows\system32> $x = dh -h; $x;

Now, if you run the linux command in PowerShell without saving to a variable, then you’ll get the session hung. To force PowerShell to get out of the hung state use CRTL-A and then CRTL-C. This will return to the Linux prompt(#).

Remember to exit ‘screen‘ by typing ‘exit‘ a few times until you get to the user ($) bash prompt.

So, with these few shortcuts, at least you should be able to work with PowerShell Open Source in Windows Bash console. I know its a little tedious but it will be rewarding at the end.

Just give it a shot, and keep learning PowerShell!

PowerShell Open Source Alpha14 and SQL Server for Linux CTP 1.1 are out!

This is Great! Microsoft keep delivering updates before Christmas just to keep us busy and excited.

To download the latest PowerShell Open Source just go to the link below:


Just remember to remove the previous version, and any existing folders as this will be resolved later.

To download the latest SQL Server vNext just check the following Microsoft blog post as the new CTP 1.1 includes version both Windows and Linux:

SQL Server next version Community Technology Preview 1.1 now available

And, don’t forget the check out the release notes as Microsoft SQL Server team has done an excellent job in providing documentation:


For those interested in how SQL Server became to Linux, check the following Microsoft Blog posts:

SQL Server on Linux: How? Introduction


Additional Tools in the Horizon

Just an FYI on some tools that recently caught my attention from Jet Brain:

1. PyCharm Community Edition (free) – Python Develoment IDE Tool available for both Windows and Linux.
2. DataGrip – SQL Developer IDE Tools for working with Databases (including SQL Server). Also available for both Windows and Linux.

And, of course, we can’t forget of Microsoft VS Code. This lightweight coding IDE works great in both Windows and Linux:



PowerShell Open Source – Windows PSRemoting to Linux with OpenSSH

I have to admit that I was waiting for this for some time. Finally, PowerShell 6.0.0-Alpha_13 can do remoting between Windows to Linux. This is Awesome!


I’m going to give you the top-to-bottom scope in order to avoid going back-and-forth between link. So, it’s all here and including tips and print-screens.

Instructions for Windows OpenSSH installation

cd ‘C:\Program Files\OpenSSH’

  • Install sshd and ssh-agent services by using the following command line:
powershell -executionpolicy bypass -file install-sshd.ps1
  • Setup SSH host keys (this will generate all the ‘host’ keys that sshd expects when its starts).
 .\ssh-keygen.exe -A


  • Open Firewall (Windows PowerShell 5.x) Server: (This command works in Windows 10)
New-NetFirewallRule -Protocol TCP -LocalPort 22 -Direction Inbound -Action Allow -DisplayName SSH


  • Or for a Workstation:
netsh advfirewall firewall add rule name='SSH Port' dir=in action=allow protocol=TCP localport=22


  • Then, to set sshd in auto-start mode and open up firewall:
Set-Service sshd -StartupType Automatic
Set-Service ssh-agent -StartupType Automatic


  • Edit the sshd_config file at the location where you installed Win32 Open SSH and make sure to enabled the following lines:
    Port 22
    PasswordAuthentication yes
    RSAAuthentication yes
    PubkeyAuthentication yes


Also, add the following line to the Subsystem section:
Subsystem powershell C:/Program Files/PowerShell/ -sshs -NoLogo -NoProfile

Finally, you must add the following line in the system path: “C:\Program Files\OpenSSH”


Failure to add this path line will cause the following error because it can’t execute sshd.exe:


If there’s a need to restart Windows SSHD services, just use the following PowerShell commands:

Stop-Service sshd
Start-Service sshd

Instructions for Ubuntu SSH installation:

  • Download using Ubuntu apt repository using sudo:
$ sudo apt install openssh-client
$ sudo apt install openssh-server
  • Make changed to Ubuntu sshd_config file to enabled some lines below:
$ sudo gedit /etc/ssh/sshd_config
  • Again, make sure to enabled the following lines:
    PasswordAuthentication yes
    RSAAuthentication yes
    PubkeyAuthentication yes
  • Add the following line to the Subsystem section:
    Subsystem powershell powershell -sshs -NoLogo -NoProfile

When done, in Ubuntu, just restart sshd service :

sudo service sshd restart

If you want to verify Ubuntu SSH is working, just type the following command:

ps -A | grep sshd

This should display a line showing sshd. If is blank, then is not on.

Connecting Linux to Windows

This is strange but, more likely, you will get an error the first time you try to connect. Just try the second try and it will work.

Enter-PSSession -Hostname earth2 -Username max_t


Connecting Windows to Linux

Again, I’ve seen the same behavior. It will fail the first time and the it will work.

Enter-PSSession -Hostname orion -Username maxt


What’s next?

After all have been tested, you can now connect from Windows to a Linux system. Then, you can execute your Linux commands from the Linux PowerShell session at your Windows Desktop. Is that amazing!!

Keeping things Simple!

Additional tips

This tips may not hurt to do:
1. winrm quickconfig
2. Run the ./InstallPsRemoting.ps1


Also, if you don’t have a domain set up, then set a workgroup environment, and adding the IP-Addresses, computer names for either Windows and Linux host file:
In Windows the *hosts file can be found under “C:\Windows\System32\Drivers\etc“, and in Linux Ubuntu can be found under “/etc/hosts“.


The editors need to be open “Run as Administrator” in order to make changes to this file. In Windows, open Powershell “Run as Administrator” the execute notepad:

notepad C:\Windows\System32\Drivers\etc\hosts

In Linux, use the sudo then the editor of choice;

sudo gedit /etc/hosts

I’m hoping this information will get you all going in doing PowerShell Remoting between Windows and Linux.

Additional Resource Information

OpenSSH Instructions at:

For Ubuntu questions: