PowerShell Core – Running GUI Scripts

May 11, 2020

DotNet Core is the new standard … But how compatible is this compared to the .NET

I Tested a few GUI scripts using PowerShell Core 7.0



Most of them where running fine.

But again not all of them did work a without errors …


Use this command to test you PS Scripts :


pwsh - file "yourfile.ps1"


I am also using the new MS Terminal to test the PowerShell Core scripts :






Looks good ! Smile

Even if this scrips uses a custom .Net Assembly (being the Charting Assembly)


Next Barcode example script works fine as well Thumbs up



But unfortunately not all scripts are working flawlessly Winking smile


Bottom line is that the compatibility is generally OK, but not quite perfect …

But the main goal is to make it cross platform compatible as possible.

Running the PowerShell Core on WSL (Windows 10 Linux Subsystem)


It is not yet quite a Party Sad smile

Makes sense because the Windows Forms Assembly is either not available on my machine or it is not yet cross platform ?

Of course I first need to install the .Net CORE on WSL Ubuntu

I will make a separate blog post about this.

This is where you need to start


Enjoy !







PowerShell Core – Power BI Gateway Management CmdLets

November 6, 2019

Keep in mind that these cmdlets are PowerShell CORE only !

First you need to check the availability of the PS CORE version on your system.

I had  6.1 preview 3 installed


So I opened the Cmd line using Admin privileges

Next started PWSH.exe

Next I run this command :

Install-Module -Name DataGateway


Next Check the available cmdlets

Get-Command -Module DataGateway*


Next I ran this command

Import-Module DataGateway


But it says my version of PS Core needs to be minimum 6.2.2 Sad smile

So first get an upgrade from here :



After upgrading your can check the version using



Next run these commands again :

import-module DataGateway
import-module DataGateway.profile


No errors now Smile

Run this command to login :


It opens the browser and return this message



Next run this command to get your Cluster ID


Next check the Gateway Status like this



So far so good Smile 

Enjoy !!

Windows 10 – Running ASP.NET Core 2.0 on Mono

August 5, 2018


After installing Mono on Ubuntu using Windows 10 WSL, see here

You can start cross compiling you ASP .NET Core 2.0 Apps to run on Mono


1. Publush for Linux

Use this command : dotnet publish -r linux-x64 -c Release


2. Install DotNet Core on Ubuntu :

First in widows go to the project folder where you find the published project see step 1.


And start the WSL there. Open command prompt in that folder and run BASH


Run these commands to install .Net Core Framework on Mono :

curl https://packages.microsoft.com/keys/microsoft.asc | gpg –dearmor > microsoft.gpg

sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg

sudo sh -c ‘echo “deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main” > /etc/apt/sources.list.d/dotnetdev.list’

sudo apt-get update

sudo apt-get install dotnet-sdk-2.1.3


3. Install and Configure Web Server Nginx

sudo apt-get install nginx

It runs on PORT 80 by default, so stop other windows webservers if needed.


next run this command :

sudo service nginx start

And test it by opening a browser in windows, you should see this webpage.



To stop the webserver run :

sudo service nginx stop


4. Configure nginx as reverse proxy server


Go in Windows to the Linux installation folder …

Open the file in Notepad++ and make the make the following changes in the DEFAULT file:



Change the default port from 80 to whatever you like, example 81

Comment out this line : #try_files $uri $uri/ =404;

Add this line proxy_pass line : proxy_pass http://localhost:5000;



You can also use the VI editor in Linux if you like this :

sudo vi /etc/nginx/sites-available/default

Now test the config changes are working :

sudo nginx -t

If you did not stop the server you can do a reload :

sudo nginx -s reload


6. Test the .Net Core App in WSL using Bash

Open Bash in the Published folder


And TEST the Linux .Net Core application like this :

dotnet FirstMvc.dll



I get an error because the Linux is CASE Sensitive. So try again using the correct command.

And the SQL Database location is not found.

Because I started it not from the default folder location, which should be C:\CoreIoT\ASPnetRazorSQLiteWsAPI\Data



But all runs well, so the .NET Core App is a try cross platfrom framework Smile


PowerShell Core – Installation on Windows 10 – Ubuntu WSL

July 4, 2018

Here you can find the correct installation instructions for Ubuntu 16 (and many more like Raspbian, …)


For PowerShell Version 7.0 see here


1. Open Bash on Windows 10



2. Install PowerShell Core

These are the commands needed to get it installed.


# Import the public repository GPG keys
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

# Register the Microsoft Ubuntu repository
sudo curl -o /etc/apt/sources.list.d/microsoft.list https://packages.microsoft.com/config/ubuntu/16.04/prod.list

# Update the list of products
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell


3. Installation process

It looks like this on Windows 10 – Bash



4. Test PowerShell


5. Let’s connect to O365 – Exchange Online




Other Commands

Make sense work fine … Get-Service doesn’t work because it is a Windows Command Winking smile



All seems OK Smile

Enjoy !

PowerShell Core – How to install the Windows Compatibility Pack

July 3, 2018

First find the correct PowerShell Core Module

Find-Module -Name PSCoreWindowsCompat | ft -a 


As you can see it only runs on Windows x64 bit !


Keep in mind that this Windows Compatibility Pack is a Temporary solution from MS, and will not stay forever :


Windows Compatibility Pack for .NET Core is not a permanent solution which will stay in codebase forever. Intention of the pack is to build a temporary bridge, allowing adoption of .NET Core to a greater extend. However, in the long term the goal stays the same – replace outdated APIs and features of .NET with newer .NET Standard-compatible alternatives.

You can download it before installing using this command

Save-Module -Name PSCoreWindowsCompat -Repository PSGallery -Path C:\Temp\ -Force 


Or install it directly

Install-Module -Name PSCoreWindowsCompat -Repository PSGallery -Verbose -Force 


As you can see it needs Administrator Privileges



Import the Module PSCoreWindowsCompat

Import-Module -Name PSCoreWindowsCompat 


You have to use the DotNet Classes instead of Cmdlets.

For instance the Compatibility pack contains the System.DirectoryServices so you can script against AD.

Like this :

$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()

$root = $dom.GetDirectoryEntry()

$search = [System.DirectoryServices.DirectorySearcher]$root

$search.Filter = "(&(objectclass=user)(objectcategory=user))"

$search.SizeLimit = 3000

$result = $search.FindAll()

foreach ($user in $result){



Compared to Windows PowerShell

Get-ADUser -Filter * | select DistinguishedName 


But it works perfectly … Smile



For .Net Core Applications see here :


Run this command :

dotnet add package Microsoft.Windows.Compatibility –version 2.0.0

Enjoy !

PowerShell Core – Connecting to O365 Exchange Online

July 3, 2018

Now that we have PowerShell running on Windows 10… let’s see if we can get use it to get access to O365 Exchange Online.


First you need to load the MSOnline Windows PowerShell  Modules in PowerShell Core.

This is done using these 3 Lines :

Install-Module WindowsPSModulePath -Force -Scope CurrentUser 

Import-Module MsOnline



If you don’t use the first 2 lines you will get an error. Because PS Core doesn’t have the MSOline Module available.

So we grab it from the Windows PowerShell.


let’s set the credentials

$UserCredential = Get-Credential


Next create the remote session to load the module


$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session



Test it using some commands





For Mac see here :


For the other O365 Services see here :


Enjoy !

PowerShell Core – Running on Windows IoT using a RPI3

July 2, 2018

As mentioned on this post

I was planning to test PowerShell Core on Windows IoT running on an ARM platform using RPI3….

PS Core Version 6.x claims to be a cross platform Smile

It is still experimental as mentioned here :


So let’s take a look :

1. Download the correct ZIP


Windows IoT running on RPI3 is a 32bit version (if you are using the free version)


2. Open the ZIP

This contains all the modules needed to run on your RPI3


Extract and copy all files over to your destination RPI3 folder.



For example c:\pscore


3. Setup Remoting on RPI3

Run this command and see PS notes :

You’ll get an error message and will be disconnected from the device because it has to restart WinRM




# Be sure to use the -PowerShellHome parameter otherwise it'll try to create a new
# endpoint with Windows PowerShell 5.1
.\Install-PowerShellRemoting.ps1 -PowerShellHome .
# You'll get an error message and will be disconnected from the device because it has to restart WinRM


4. Connect to the PS Core on your RPI3

# Be sure to use the -Configuration parameter.  If you omit it, you will connect to Windows PowerShell 5.1
Enter-PSSession -ComputerName <deviceIp> -Credential Administrator -Configuration powershell.6.0.2



5. How to run Windows PowerShell modules in PowerShell Core

Run these 2 commands to get access to the Windows PS modules


Install-Module WindowsPSModulePath -Force -Scope CurrentUser 




Or this way for a custom module

Import-Module "C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX.psd1"
Get-Command *au3*




6. Test PS Core on your RPI3


All runs as expected Smile


But keep in mind that not all functions are supported (yet)



Even if it says so see help Sad smile



Running PowerShell Core on Linux or Mac see here to get started :



Enjoy !

PowerShell Core – Installing and Testing

July 2, 2018

PowerShell Core has reached version 6.1xxx at this moment …


Why do you need PS Core v6.1.x





How to install

Since PS Core is a cross platform distribution, just pick the one you need Smile



Download and run for a Windows 10 SxS installation




Select Open PS Core

or start is manually



In order to run PS Core you need to use the pwsh.exe commandline and not powershell.exe !

Check the PS Core version :

run pswh.exe –v


Or the famous command




PowerShell core does not have all the modules of the full blown version available.

But it has already a lot… run


it will list about 425 commands



If you need more :

Windows PowerShell Compatibility Pack

With the announcement of the Windows Compatibility Pack for .NET Core for .NET Core, PowerShell Core will regain some APIs that had been dropped in the transition to .NET Core.  This means we can re-enable some cmdlets that weren’t part of the PowerShell Core 6.0 release: WMI, EventLog, and PerfCounters.  In addition, some highly requested APIs will be available which means that some existing Windows PowerShell modules might just work in PowerShell Core 6.0.  This module will replace the WindowsPSModulePath module to add the Windows PowerShell $env:PSModulePath to PowerShell Core 6.0.  Finally, we can use this module to optionally add back some aliases that we removed from PowerShell Core 6.0 that exist in Windows PowerShell.

Example it allows you to run encrypted commands as well out of the box… Smile



For a full list of command line options run pwsh.exe /? (or –h or –help or …. Winking smile )

Most relevant are :

pwsh -NoExit -Command Get-Date



Some of the commands you need to run using Administrator privileges or you get this error :


pwsh -Command {Get-WinEvent -LogName security} or pwsh -command “& {Get-WinEvent -LogName security}”



You can run Windows PowerShell modules in PowerShell Core on Windows


Install-Module WindowsPSModulePath -Force -Scope CurrentUser 



Next episode I will test it the PS Core on an RPI3 running Windows IoT, see here


Windows Core IoT – ASP DotNet Core Razor Pages & SQLite & Web Service on a Raspberry PI3

May 28, 2018

Building a Web Server App using ASP .Net Core using a SQLite Database and a Web Service starts here using this example.


I gave it a little twist in order to get it to use an SQLite Database and add a Web Service to it.

This means you need to follow page 1 of 8 from this Tutorial to get the full deal. I only did page 1 & 2.

But make the necessary change mentioned below.

Keep in mind that the we will only use the command line options, and no bulk load of software needed to install Smile

Requirements are that you have Dotnet Core installed.

And have the DB using EF Tools installed from NuGet

Creating the  .Net Razor App

1. Create a new blank RAZOR project

Create a new folder in your PC and run the command to create a new RAZOR project


Command : dotnet New Razor

This will create a new blank Razor project

2. Install the DB using EF Tools

Go to Nuget and look for this package


I used the version 2.1.0-rc1-final

Run this command :

dotnet add package Microsoft.EntityFrameworkCore.Tools –version 2.1.0-rc1-final

After installation you can test is using this command :

dotnet ef


3. Add more packages needed

dotnet add package Microsoft.EntityFrameworkCore.Tools.DotNet –version 2.1.0-preview1-final

dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design –Version 2.0.0

dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Utils –Version 2.0.0

4. Add missing other packages

Correct the project .Json package references, by adding the missing packages from the Nuget Site :


<Project Sdk="Microsoft.NET.Sdk.Web">
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Utils" Version="2.1.0-preview2-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.1.0-preview1-final" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.8.0" />
    <PackageReference Include="SQLitePCLRaw.bundle_green" Version="1.1.10" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.0.2" />
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />

Next run this command :

dotnet add xxxxx form the .NET CLI command.


It downloads and installed the package selected on the NuGet site

Check you .Json Project file again afterward and continue with the rest of the missing packages

When finished run command :

dotnet Restore

5. Add the missing code to generate the DB

(Or generate the code based on an existing DB using Scaffolding)

Example : Create a Models folder. In the Models folder, create a class file named Student.cs

Content see example Microsoft site :



6. Create the xxxxContext DB context

xxx = School in my case


In the Data folder create SchoolContext.cs


This is where I modified the code to use SQLite instead of a Local DB


In Startup.cs add the missing references (Using xxx) add the DB Context reference :


Add the DB Context reference :

services.AddEntityFrameworkSqlite().AddDbContext<SchoolContext>(); // Added

In the Data folder, create a new class file named DbInitializer.cs see MS Example Site


Which gets called by program.cs


This will create the Database Tables, Fields and Records using the Entity Framework Tools.

Opposite, you can create View Pages from an existing Database using Scaffolding with the Entity Framework Tools too… Winking smile

Use a command like this to generate an EF Model from and existing Database

dotnet ef dbcontext scaffold “Datasource=C:\CoreIoT\ASPSQLite\Nwind.db” Microsoft.EntityFrameworkCore.Sqlite -o Models -c “DatabaseContext” –f

7. Generate the View pages based on the model you created before :

Courses : dotnet aspnet-codegenerator razorpage -m Course -dc SchoolContext -udl -outDir Pages\Courses –referenceScriptLibraries

Instructor : dotnet aspnet-codegenerator razorpage -m Instructor -dc SchoolContext -udl -outDir Pages\Instructors –referenceScriptLibraries

8. Correct the ERRORS, if needed…

When running the command in step 6 you can get ERRORS.


Globally change _context.Student to _context.Students (add an “s” to Student)


Quote from MS Site :

There are 7 occurrences found and updated. This is a bug and the hope to fix this bug in the next release.

=> TEST THE APP to see all errors are gone :


cd to your project folder, next use this command :

Dotnet Run

9. BEFORE publishing add the following string in the program.cs and republish again.



10. Publish for RPI3 – ARM

Run this command : dotnet publish -r win8-arm

11. Copy from Publish to your RPI3

Copy the Files from the PUBLISH folder to your RPI3.

ASPRazor -> C:\CoreIoT\ASPnetRazorSQLiteWsAPI\bin\Debug\netcoreapp2.0\win8-arm\publish\


Next MAKE SURE your FOLDER STRUCTURE on the RPI3, is exactly the same as it was on your PC before Publishing.


Or you run into this error : ‘Unable to open database file’

Next COPY the SQLite Database to your RPI3. Because this is NOT included when publishing using DotNet Core to win8Arm

12. Test the .Net Razor App on your RPI3

Login using PowerShell WSMAN to your RPI and start the app.


Go to the URL (it can take a while before all is loaded ….)


Let access the database ?


Let’s add some data ?



Haleluja, this is fully functional and cross platform !!

Adding a Web Service to the .Net Razor App

Next I will add it to the site to see we can access the data using a Web Service API.

Again instead of using the full blown Visual Studio we will only use the command line options.

Because we don’t want to install an elephant weight of software !


Actually Visual Studio uses all these commands in the background too … Winking smile

Run this command :

dotnet aspnet-codegenerator controller -api -name StudentAPIController -m Student -dc SchoolContext -udl -outDir Models\API –referenceScriptLibraries -f


see the result


You also have the option to generate XML instead of JSON


Check the result !!


This is how you you select ID 5

ID = 5


It contains GET / POST / PUT / DELETE methods !

Accessing the Web Service using PowerShell



$URL = "http://localhost:5000/api/StudentAPI"

$APIService = Invoke-RestMethod -Uri $URL

$APIService | select ID, lastName, firstMidName 

After copying to your RPI3 you can change the URL to http://rpi3:5000/api/StudentAPI

And test it …


As you can see all runs fine, no Visual Studio needed …. Smile

So now you have a Web Service running on your RPI3, who could have imagined this … ?

Use Case :

Since you now have an SQLite DB running your can feed it with your RPI3 SENSOR data and read it out using the Web Smile

or even as a Web Service as demonstrated above …

Enjoy !

Windows Core IoT – ASP DotNet Core Razor Pages on a Raspberry PI3

April 20, 2018

Continuing on based on my prior posts

.Net Core on RPI3

SQLite on RPI3

I am going to explain how to use Windows IoT and ASP .Net Core on a RPI3.

As of version 2.0 we now can create ASP Razor webpages in .NET Core.

Remember that in the past I made some post about Web Matrix

That is in fact the predecessor of ASP .Net Core. Read more here

How to use Razor Pages in ASP.NET Core 2.0

Start with installing the DotNet Core Template to begin with

Run command :

dotnet new Razor -n ASPnetCoreRazor -o C:\CoreIoT\ASPnetCoreRazor


Next Run the Template Application on your Windows PC.

Use command :

cd C:\CoreIoT\ASPnetCoreRazor

dotnet Run


Voila as simple as that Smile


Next Publish it for Windows IoT on a RPI3 Architecture

Run command :

dotnet publish -r win8-arm


Copy the files to your RPI3 from C:\CoreIoT\ASPnetCoreRazor\bin\Debug\netcoreapp2.0\win8-arm\publish


Connect to RPI3 using PowerShell remote session and start the ASPNetCoreRazor.exe Application


No connection … ? Sad smile



1. You need to open the Firewall Port 5000 on your RPI3 first.

Run command :

netsh advfirewall firewall add rule name=” ASPnetCoreRazor ” dir=in action=allow protocol=TCP localport=5000


2. Modify the Template Program.cs script

And add this line : .UseUrls(http://*:5000)


Publish again :

dotnet publish -r win8-arm


Copy the files back over to your RPI3 :


Next connect to RPI3 using PowerShell and start the app ….



Open the browser and go to : http://rpi3:5000


It runs as expected !! Smile

So now we know how to create RAZOR pages, the door is open to start experimenting with the RAZOR syntax.

As well as integrating SQLite database using the ASP .NetCore Razor Front End….

Enjoy !