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

 

image

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 :

image

 

image

 

image

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

image

 

But unfortunately not all scripts are working flawlessly Winking smile

image

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)

image

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

image

So I opened the Cmd line using Admin privileges

Next started PWSH.exe

Next I run this command :

Install-Module -Name DataGateway

image

Next Check the available cmdlets

Get-Command -Module DataGateway*

image

Next I ran this command

Import-Module DataGateway

image

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

So first get an upgrade from here :

https://github.com/PowerShell/PowerShell

image

After upgrading your can check the version using

$PSVersionTable

image

Next run these commands again :

import-module DataGateway
import-module DataGateway.profile

image

No errors now Smile

Run this command to login :

Login-DataGateway

It opens the browser and return this message

image

image

Next run this command to get your Cluster ID

Get-DataGatewayCluster

Next check the Gateway Status like this

Get-DataGatewayClusterStatus

image

So far so good Smile 

Enjoy !!


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, …)

https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell-core-on-linux?view=powershell-6

For PowerShell Version 7.0 see here

https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7

1. Open Bash on Windows 10

image

 

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
pwsh

 

3. Installation process

It looks like this on Windows 10 – Bash

image

 

4. Test PowerShell

image

5. Let’s connect to O365 – Exchange Online

image

Get-Mailbox

image

Other Commands

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

image

 

All seems OK Smile

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 
 
Add-WindowsPSModulePath

Import-Module MsOnline

 

image

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

image

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

image

 

Test it using some commands

image

Get-User

image

 

For Mac see here :

https://www.cgoosen.com/2017/03/connecting-to-exchange-online-with-remote-powershell-from-a-mac/

For the other O365 Services see here :

https://www.michev.info/Blog/Post/1954/powershell-core-and-office-365

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 :

https://docs.microsoft.com/en-us/powershell/scripting/setup/powershell-core-on-arm?view=powershell-6

So let’s take a look :

1. Download the correct ZIP

https://github.com/PowerShell/PowerShell/releases

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

image

2. Open the ZIP

This contains all the modules needed to run on your RPI3

image

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

 

image

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

 

image

 

# 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

image

 

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 

Add-WindowsPSModulePath

 

image

Or this way for a custom module

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

 

image

image

6. Test PS Core on your RPI3

image

All runs as expected Smile

 

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

image

 

Even if it says so see help Sad smile

image

 

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

https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell-core-on-linux?view=powershell-6

https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell-core-on-macos?view=powershell-6

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

https://blogs.msdn.microsoft.com/powershell/2018/01/10/powershell-core-6-0-generally-available-ga-and-supported/

https://docs.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-core-60?view=powershell-6

https://blogs.msdn.microsoft.com/powershell/2018/01/24/powershell-core-6-1-roadmap/

 

How to install

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

https://github.com/PowerShell/PowerShell/releases

 

Download and run for a Windows 10 SxS installation

 

image

 

Select Open PS Core

or start is manually

image

Testing

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

image

Or the famous command

$psversiontable

 

image

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

But it has already a lot… run

get.command 

it will list about 425 commands

image

 

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

image

 

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

image

 

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

image

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

image

 

You can run Windows PowerShell modules in PowerShell Core on Windows

 

Install-Module WindowsPSModulePath -Force -Scope CurrentUser 

Add-WindowsPSModulePath

 

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

Enjoy!