Florida PowerShell User Group Online Meeting – Thursday February 23rd, 2017

Topic:  Understanding Bash On Windows 10

Description: Come and learn how to setup and use Bash On Windows 10. Learn the tips and tricks to use PowerShell and Python together. At the same time, there are some differences in working with script files between Bash and Windows systems. We’ll be seen how to use efficiently use Windows apps with Python scripts on Bash. Lots of demo!

Meeting starts at: 6:30pm(EST)

Register at: https://www.eventbrite.com/e/florida-powershell-user-group-monthly-meeting-february-2017-tickets-31689059831

Posted in Bash, Linux Bash, PowerShell, SQL Server, Ubuntu, Windows 10 | Comments Off on Florida PowerShell User Group Online Meeting – Thursday February 23rd, 2017

PowerShell – Exciting January 2017 New Releases

Here are a couple of interesting announcements back in January 2017:

SAPIEN 2017 all products released on 1/17/2017: https://www.sapien.com/software
Check out what’s new on PowerShell Studio 2017:

Windows Management Framework 5.1 RTM released on 1/19/2017.  More information at the following links:

Download from: https://www.microsoft.com/en-us/download/details.aspx?id=54616

Also, don’t forget to check out Microsoft Virtual Academy (MVA) and look for existing “free” PowerShell training topics: https://mva.microsoft.com/

Current list of MVA PowerShell Topics:

Posted in PowerShell | Comments Off on PowerShell – Exciting January 2017 New Releases

Windows 10 Bash and PowerShell Redux

In my previous blog “http://www.maxtblog.com/2016/10/running-powershell-in-windows-10-bash-workaround/“, I was able to find a workaround to how work with PowerShell Open Source in Windows Bash subsystem.  But now, I found a better way using the Ubuntu Desktop component.

It’s a known fact, if you install PowerShell Open Source in Windows 10 Bash subsystem, that it won’t work correctly. As soon as start typing $PSVersionTable and press enter, the cursor goes to the top of the screen. And, you keep typing and it gets very ugly.

Now, what if I tell you, I found the way to run PowerShell Open Source without any of these issues. Just like running it like it was installed in a Linux environment. No issues with the cursor going crazy and able to page up and down.

The following are the steps required to run PowerShell Open Source.

Windows 10 Requirements

You *MUST* use the following Windows X Server application. Just proceed to Download and install VcXsrv Windows X Server:

Also, proceed to Download (to be install later) PowerShell Open Source. Go to the following Github link, and pick the Ubuntu 16.04 version: for Ubuntu 16.04:

For best results, make sure to be on Windows 10 Insider Build 15007.rs_prerelease.170107-1846.

If previously installed, reset your Windows 10 Bash Subsystem installation, by executing to following commands on either DOS or PowerShell prompt:
1. Uninstall command: lxrun /uninstall /full
2. Clean Installation: lxrun /install

*Note: I’m assuming you’ve been recently checking out Bash in Windows 10. If not, go to “Control Panel | Programs and features” then go to “Turn Windows features on or off” and enable “Windows Subsystem for Linux (Beta)“. By the way, you must have “Developer mode” enabled under “Settings | Update and Security | For Developers” section.

Then, on the Windows menu, look for the “Bash on Ubuntu on Windows” icon and open the console. Make sure Bash is installed and working in Windows 10.

Bash Subsystem Requirements

Now, we need to start installing some additional components in our Bash environment.  Please notice I can use PowerShell console and open “Bash“.  Also, while installing these Linux packages, make sure to open any console “as Administrator“.

Then, in Bash prompt, use the Super User privilege command “sudo su” before installing these packages.

sudo su

I recommend to use the following two command for the purpose of getting both available updates and upgrades to Bash installed packages. You could use these command on a regular basis to keep you subsystem up-to-date.

sudo apt update

sudo apt upgrade

The following commands will install the Ubuntu Desktop and takes about 1hr to complete. Patience is a virtue!

sudo apt install ubuntu-desktop

In some cases, at the end of the installation you will either see no errors, or it will end with the following message: “E: Sub-process /usr/bin/dpkg returned an error code (1)“.

Now, the next package installation install the desktop setting manager application you will need to use later;

sudo apt install compizconfig-settings-manager

So after all is done, use the “exit” command to get out of the Super User session and get back to your user session.


Installing PowerShell

Now, we are ready to install PowerShell Open Source. Remember, if you follow above Windows 10 Recommendation section, you have already downloaded PowerShell. This file will be located in your “..Username\Downloads” folder.  From the Bash prompt, you’ll probably be seen “username@SystemName:/mnt/c/Users/username$” when you open the console as a regular user (non-Admin privilege).

The following commands change folder location to where the PowerShell installation package was saved and the execute the package.

cd Downloads
sudo dpkg -i powershell_6.0.0-alpha.14-1ubuntu1.16.04.1_amd64.deb

This package installation should end without any errors. Don’t open PowerShell yet!

The Ubuntu Desktop

First, in Windows 10, we need to start our “VcXsrv Windows X Server” application by clicking the Windows X Server “Launch” icon. Pay close attention to the field labeled “Display number” should have the value ‘0‘ and pick the “One large window“. Then clicking “Next” to accept all default values.

This will open a blank Windows X Server display.

Now, open “Bash on Ubuntu on Windows” prompt, and at this point there’s no need to open “as Administrator”. Type the following commands to start the “Ubuntu Desktop” in Windows 10:

export DISPLAY=localhost:0

This command will allow the any gui application to interact with our Windows X Server service.

Then, run the command ‘ccsm‘ to configure the Ubuntu Desktop settings: (This is a one time setup)


Click “OK” to continue making settings changes following the images below.

After updating the settings, click “Close

To proceed to start the Ubuntu Desktop, just execute the following command:


You will notice there are some applications available to use.

Let’s concentrate of the ‘File’, ‘Text Editor’, and ‘Terminal’. You can manually execute some gui applications from the bash command prompt such as:
1. For File Browsing execute: nautilus or ‘sudo nautilus’ with elevaded security.
2. For Text Editor execute: gedit or ‘sudo gedit’ with elevated security.
3. For Internet browsing: firefox

Now, we are ready for PowerShell.

PowerShell in Windows 10 Bash

At the Ubuntu Desktop just right-click and pick “Open Terminal”. Then, type “powershell” and press enter.

Then execute the following powershell commands:


As you can see we, now PowerShell is working in Windows 10 Bash thank to Ubuntu Desktop. But, keep in mind, Ubuntu Desktop is not supported in Windows 10 Bash subsystem. At least, you can give it a test drive.

By the way, you can use your favorite PowerShell Editor

BONUS Section

Important Path to Remember, in case you’ll find where things are in Windows 10 Bash Subsystem.

Windows 10 BASH folders:

Bash file path to Windows folders:

Where PowerShell Open Source folder are located in Bash Subsystem:

Additional Information:
Information about installing Ubuntu Desktop in Windows Bash:
— See link for info: https://github.com/Microsoft/BashOnWindows/issues/637


Posted in Bash, PowerShell, Ubuntu, Windows 10 | Comments Off on Windows 10 Bash and PowerShell Redux

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!

Posted in PowerShell | Comments Off on PowerShell – Useful Windows Bash commands to remember

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:



Posted in PowerShell, SQL Server, Ubuntu, Windows 10 | Comments Off on PowerShell Open Source Alpha14 and SQL Server for Linux CTP 1.1 are out!

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:

Posted in Bash, PowerShell, Ubuntu | Comments Off on PowerShell Open Source – Windows PSRemoting to Linux with OpenSSH

PowerShell – Working with Python and SQL Server

As you all know with the release of PowerShell Open Source and SQL Server on Linux are open doors to cross-platform developments. But is has been going on for awhile as Linux languages like Python, Ruby, Java and PHP has been already available for Windows.

So, all comes down in setting your tools to allows cross-platform development in order to minimize the headaches of tweaking or altering your code between environments.

As PowerShell is the main technology for automation in Windows Datacenters Infrastructure, now becomes clear its importance in other non-Windows Operating Systems. The way I see it, Windows Admin has the advantage with PowerShell as the Linux Admin has the upper hand with Bash/PHP/Python. Here’s where we can collaborate and work with each other.

PowerShell and Python

I’m assumning you have already have installed PowerShell Open Source (powershell_6.0.0-Alpha.xx) as Windows PowerShell already exist.

We need to make sure we install Python in both Windows and Linux environments.
1. Download Python for Windows: https://www.python.org/
2. Select Python version: 2.7 or 3.5 (I’m using Python 3.5)

*Note: My Linux OS is Ubuntu 16.04.1 which already included Python 2.7. So, I have installed Python 3.5.

After the installation, there are a few more steps to do as we’ll be connecting to a SQL Server in any of our environments.

In Ubuntu, to install Python version 3.5 plus needed modules you need to execute the *following ‘bash’ line:

$ sudo apt install unixodbc-dev
$ sudo apt install python3
$ sudo apt install python3-pip
$ sudo pip3 install --upgrade pip
$ sudo pip3 install --upgrade setuptools
$ sudo pip3 install --upgrade wheel
$ sudo pip3 install pyodbc

*Note: I’ve notice that sometime doing a “pip3 install –upgrade ..” will fix some issue with modules. But, during any python module installation it will let you know when to run the command.

In Windows, just need to install the module for connecting to SQL Server using Python ODBC

c\:> pip3 install pyodbc

Now, you can open Python from any of your Windows Console: DOS, Windows PowerShell, or PowerShell Open Source.

In order to execute *Python 3.5 in Ubuntu, simple type:

$ python3.5

*Note: Just an FYI. You can use the “Update-Alternative …” bash command to set the default python to 3.5.

Testing PowerShell and Python

Open any PowerShell Console, on either Windows or Linux, you just type Python at the prompt.


You will immediately see the Python prompt, and just type the following python code:

import sys;
cur_version = sys.version;


Now, in PowerShell, try typing a python code and save it to a PowerShell variable:

C:\WINDOWS\system32> $v = python -c @"
import sys;
cur_version = sys.version;


As you see, PowerShell and Python interact very well. The same applies in the Linux Ubuntu environment.

Python and SQL Server

For this section we previously installed the python module pyodbc which is needed to connect via ODBC to any SQL Server on the network giving the proper authentication method.

The following sample code can be found this link: https://www.microsoft.com/en-us/sql-server/developer-get-started/python-ubuntu

I did slightly modify the python code to add a new record to an existing database. And, to run it within Powershell:

## - Build Here-String variable with Python code:
$runpythonsql = @"
import pyodbc

database = 'sampledb1';
cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};Trusted_Connection=yes;SERVER=' + server+';PORT=1443;DATABASE='+database);
cursor = cnxn.cursor();

#Insert Query
tsql = 'INSERT INTO Employees (name, location) VALUES (?,?);';
if cursor.execute(tsql,'Maximo Trinidad','Puerto Rico'):
print('Inserting record to Database Sampledb1 was Successful!');


## - Execute Python code from within PowerShell
$r = python -c $runpythonsql;

## - Display Result of Inserted data:




As you can see, PowerShell and Python can go hand-in-hand. They can be a perfect match cross-platform.

For more information about PYODBC, click on the link: https://github.com/mkleehammer/pyodbc


Posted in PowerShell | Comments Off on PowerShell – Working with Python and SQL Server

PowerShell Open Source – Looking into Windows 10 Bash Linux subsystem and PowerShell

This is an FLPSUG October 27th Online meeting that, due to a Windows 10 update issue, had to be rescheduled to November 3rd.

Topic: Looking into Windows 10 Bash Linux subsystem and PowerShell

We’ll be taking a tour into Windows 10 Bash Linux subsystem. I’ll be sharing some tips on how to work with Bash, and the workaround to make PowerShell in side BASH. This is the perfect environment to start learning about Linux while you work in windows. We’ll be take advantage of how-to use cross-platform Open source product(s).  All this and more from Windows 10.

Click to view the video: https://youtu.be/1AJ7ZlZRIj0


Posted in PowerShell | Comments Off on PowerShell Open Source – Looking into Windows 10 Bash Linux subsystem and PowerShell

PowerShell Open Source – Take advantage of ‘#Requires -Version’ and new variables

Now that PowerShell Open Source is evolving, we need taking advantage of some if it features to build cross-platform scripts. Also, a good way to test the script functionality is to use either Linux or Windows 10 Bash environments.

Just keep in mind, for now you won’t be able to run you existing Windows PowerShell scripts or modules in another OS. Unless, you concentrate that write your scripts only using the PowerShell Core module. PowerShell Open Source is evolving.

Also, there are already modules available that can be use cross-platform thru PowerShell Gallery, and NuGet. Just make sure to search of Linux or Mac OS scripts.

Find-Module -tag linux


Using PowerShell existing features

Now, when creating cross-platform scripts, I found very useful to have the “ #Requires -Version x” statement. This statement is available in all versions of PowerShell.

Next, is to take advantage of the new PowerShell Open Source variables:
– IsCoreCLR
– IsLinux
– IsWindows


By just adding a conditional statement (“if”) to check which OS environment you are running the script. This makes it so convenient and portal across multiple OS environments.

Sample Script

To demostrate, *here’s a sample script for searching Debian packages I use on my Window 10 and Linux systems:

<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.129 Created on: 10/31/2016 2:18 PM Created by: Maximo Trinidad Organization: PutItTogether Filename: CrossPlatTest.ps1 =========================================================================== .DESCRIPTION A description of the file. #>

#requires -version 6
function Get-DebianFiles
Param (
[string]$FileExtension = "*.deb"
write-host "Only in PowerShell 6.0"
if ($IsWindows -eq $true)
$PackageLocation = 'C:\Users\mtrinidad\Downloads';
Write-Verbose "Windows Selected" -Verbose;

if($IsLinux -eq $true)
$PackageLocation = '/mnt/c/Users/mtrinidad/Downloads';
Write-Verbose "BASH Selected" -Verbose;

Get-ChildItem $PackageLocation -File -Filter $FileExtension -Recurse;

#. C:\TempPoshXplat\Scripts\PowerShell\CrossPlatTest.ps1

## Get-DebianFiles -FileExtension "*.deb";
Get-DebianFiles -FileExtension "*.deb";

## ---------- end of scripts -----------##

*Note: In order for the ” #Requires -Version..” statement to work, it need to execute from a script file *.ps1. The statement won’t work from inside a function.

The above script is required to run in PowerShell 6 because is using both new variables: IsWindows and IsLinux. Keep in mind, this sample have hardcoded path to where I’ve stored my debian packages and it can be improved more.



There still a lot of work to be done in both Windows 10 Bash and PowerShell Open Source. The variables to properly identify the OS in non-Windows system hasn’t been implemented yet. But, it will be available sometime soon.

In the meantime, keep exploring, testing, and contributing in Github!

Posted in PowerShell | Comments Off on PowerShell Open Source – Take advantage of ‘#Requires -Version’ and new variables

SAPIEN PowerShell Studio – Simple sample using ComboBox in forms


The Form

This is a simple form showing the ComboBox component using PowerShell Studio.



For this sample I’m using a Simple Form in order to add components to it. In this case a ComboBox Component. At the same time we are adding a Label Component which I will use to display the selected item from the ComboBox.


The Code

Notice in the “Script” pane, when you create the form and added the ComboBox, it will also add a new function: “Load-ComboBox“.


This function,m under commented help, will give you examples on how to load items into the ComboBox component for the form to use.


This will make your life easy while building your forms.

But, you can provide your own script code to populate the component. Here’s an example code snippet:

## - Custom Code to Load into ComboBox:
[array]$lstItems = ("Server1", "Server2");
$cbPickLstItems.Text = $lstItems[0].ToString();

Of course, you can put the code into a function to keep consistency across the application.

Next, would be to create the code to add items into the ComboBox and compile the application. This code will be added into the “$ComboBox_Load” event. I’m using the SAPIEN already provided “Load-ComboBox” function.


Now, just run the application, save, and see the results.




The code we provided will only select the item. You’ll notice the results is not displayed yet.

In order to display the selected item we need to add another event called “.._SelectedIndexChanged“.

In order to create this event, go to the form and double-click on the ComboBox component and then we add the following code in the “$combobox1_SelectedIndexChanged” event.

$results = $ComboBox1.SelectedItem.ToString();
$labelResultsHere.Text = $results;

Then, run the application event and we finally see the displayed selected results.




It’s always fun to build quick apps with PowerShell Studio!

Posted in PowerShell | Comments Off on SAPIEN PowerShell Studio – Simple sample using ComboBox in forms