Visual Studio Code – Solution Explorer .Net Core

July 31, 2018

If you don’t want to run all the command line command of DotNet Core like here.

You can start using the Visual Studio Code for .NET Core with the VSCode Solution Explorer

image

https://marketplace.visualstudio.com/items?itemName=fernandoescolar.vscode-solution-explorer

image

 

Install and Reload

image

 

image

Go to menu VIEW => EXPLORER

image

Create a new Project file from the START page

image

You can see the command it ran, in the Debug window.

image

 

Next it it ask you to open up a TEMPLATE file in the bottom right corner

image

Click YES

It will open the TEMPLATE Window to choose from :

image

It that did not open the Template window you can trigger it manually here.

Right click on the Solution file => Add New Project

image

Follow the questions asked and it will create a new Project from the Template and Programming Language chosen.

Again the commands show up in the Debug Window

image

As you can see it created nicely the new .Net Core Project

image

 

Benefit of this extension is that you don’t need to run all the command manually.

And you don’t need to install a ton of software like Visual Studio on your machine …. Smile

image

You can also add .NET Core Test Explorer Extension to VS Code for Unit testing

image

More extensive info you can find over here

Enjoy !

Advertisements

Visual Studio Code – How to run PowerShell or AutoIT

July 25, 2018

What is Visual Studio Code (VSCode) ?

Visual Studio Code is a cross platform source code editor for Windows, Linux and macOS, that support a multitude of programming and scripting languages.

https://en.wikipedia.org/wiki/Visual_Studio_Code

 

image

 

And more using extension …

https://marketplace.visualstudio.com/vscode

image

More then 1700 extensions available, only for Code language alone …

 

Install VSCode :

https://code.visualstudio.com/download

 

VSCode Architecture ?

VS Code is fully decoupled from the specific debugger and this architecture allows VS Code to debug anything, as long as there’s a Debug Adapter available, as illustrated here:

image

 

Why using VSCode ?

If you don’t want to use the full blown Visual Studio, which is a ton of software on you computer !

But still want to have the syntax highlighting, code intellisense, and more then VSCode is the real deal for you.

Big community and training videos

https://code.visualstudio.com/community

 

Extensions ?

There are many extensions available that gives VSCode extra functionality…

On of them is running code inside VSCode, like PowerShell and AutoIT, and hundreds of many more !

So you don’t need to use the PowerShell ISE or SciTE anymore, keeping all different code development & debugging in 1 tool Smile

 

Solution :

1. install the PS Code extension:

https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell

 

2. Restart VS Code

 

3. Test a PS Script

Open a PS1 script and press F5.

image

See here for more info :

https://4sysops.com/archives/how-to-run-powershell-code-in-vscode/

 

The same goes for AutoIT Smile

1. Install the extension

2. Restart VSCode

3. Test a au3 Script

Keyboard Shortcuts :

  • Run Script: F5
  • AutoIt Check: Ctrl+F5
  • Compile Script: Ctrl+F7
  • Build Script: F7
  • Run AutoIt Help: Ctrl+F1
  • Run Au3Info: Ctrl+F6
  • Debug to MsgBox: Ctrl+Shift+D
  • Debug to Console: Alt+D
  • Run Koda: Alt+M

image

 

More info on how to Configure VSCode :

https://4sysops.com/archives/vscode-as-a-console-for-powershell-core-6-part-1-multiple-shells/

 

Enjoy!


Windows Core IoT – Stop Cortana process

July 21, 2018

When running the latest version of Windows IoT, it will install the Cortana service as well …

Which can take quite some unnecessary memory and CPU from your little RPI3 Sad smile

This way you can find out how to stop it manually, because there is no way you can do it at boot time ?

When starting Windows IoT you can see the Cortana process is running :

image

If you select STOP you notice it doesn’t stop from the first time ?

You need to repeat it multiple times….

Uninstalling did not work, IoT crashed afterwards and stopped working.

Let’s see if we can find a different way ?

We will make use of some command line tools, see here :

First lets list all processes using TLIST.EXE

image

You will notice you won’t find anything related to Cortana at first sight…

Let’s run TLIST.EXE –v

image

Just like to the full Windows 10 you find out that SearchUI.exe is hosting the Cortana process.

Let’s try to kill it now using the KILL.EXE command :

image

Using the Process ID or the Process Name …

Indeed the process stopped immediately.

image

I noticed that after a while the process starts again automatically ?

So now we can quickly kill it again when needed.

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

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 – 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 !

clip_image002

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

http://lunarfrog.com/blog/windows-compatibility-pack-net-core

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

clip_image004

 

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){

$user.Properties.distinguishedname 

} 

Compared to Windows PowerShell

Get-ADUser -Filter * | select DistinguishedName 

 

But it works perfectly … Smile

image

 

For .Net Core Applications see here :

https://www.nuget.org/packages/Microsoft.Windows.Compatibility

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 
 
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 !