Installing PowerShell Core in Server Core

In the following Virtual machine scenario, I got one Server Core with Active Directory (Build 16299) and Windows 10 (Build 16299) joined to my new domain. Both Build 16299.
On my Windows client I create a shared folder named “SharedFiles”, where I copy over the latest MSI version of PowerShell Core “PowerShell-6.0.0-win-x64.msi”.

Then, on the Server Core I’m going to create a map drive to my Windows client shared folder to then run the MSI installation from Windows PowerShell Console.

Install Steps

Here are the steps on Server Core Command Prompt:

1. Open Windows PowerShell:

[sourcecode language=”powershell”]
## – Start PowerShell:
PowerShell

[/sourcecode]

2. Map network drive to Windows Client shared folder, then change drive:

[sourcecode language=”powershell”]
## – Map network drive:
New-PSDrive -Name “m” -PSProvider “FileSystem” -Root “\\systemname\sharedfolder”;

## – Change to drive to “m:” and verify the MSI file is there:
m:
dir

[/sourcecode]

3. At the “m:” drive, execute the installation with the following command:

[sourcecode language=”powershell”]
## – Start installing PowerShell Core:
msiexec /i .\PowerShell-6.0.0-win-x64.msi /q

[/sourcecode]

4. As this is a silent installation, so give it a few minutes, then exit to the command prompt
[sourcecode language=”powershell”]
## – type “exit” to get back to the command prompt
exit

## – Change directory to PowerShell Core, and execute pwsh.exe:
cd “C:\Program Files\PowerShell\6.0.0”
pwsh

[/sourcecode]

Setting ExecutionPolicy and Update Help

It has become a routine that after first time openning Powershell, that we need to: 1) set the ExecutionPolicy, and update the help documentation:

So, setting the execution policy, pick the one you need. The most common ones are: “RemoteSigned”, “ByPass”, “AllSigned”, “Unrestricted”.

[sourcecode language=”powershell”]
## – Example setting ExecutionPolicy as “RemoteSigned”
Set-ExecutionPolicy -ExecutionPolicy “RemoteSigned”;

[/sourcecode]

Then, its very important to update the help documentation. I had the tendency to always include to parameter “-Force“:

[sourcecode language=”powershell”]
## – Updating Help documentation:
Update-Help -Force

[/sourcecode]

And, you’re ready to work with PowerShell Core on Server Core.

Oh! How to uninstall PowerShell Core

Let go a little further. Here are the steps to successfully uninstall PowerShell Core on Server Core.
Open Windows PowerShell, make a list of all installed products using Get-WMIObject command:

[sourcecode language=”powershell”]
## – Listing installed products
get-wmiobject Win32_Product `
Select IdentifyingNumber, Name, LocalPackage `
| Format-Table -AutoSize;

[/sourcecode]

This will confirmed PowerShell Core is installed. Pay close attention to the “IdentifyingNumber” property which is really the product GUID.

Now, we can proceed to uninstall PowerShell Core. There are two way to execute a product MSI uninstall:

1. Providing the installation path with filename:

[sourcecode language=”powershell”]
## – Executing Uninstall MSI silently and write to log file: (Using filename)
msiexec.exe /x “c:\filename.msi” /qn /lv “C:\msilogfile.log”

[/sourcecode]

2. Using the IdentifyingNumber (Product GUID) listed when executing the Get-WMIObject:

[sourcecode language=”powershell”]
## – Executing Uninstall MSI silently and write to log file: (Using Product GUID)
msiexec.exe /x ‘{11111111-1111-1111-1111-11111111111X}’dir /qn /lv “C:\msilogfile.log”

[/sourcecode]

Image below doing MSI uninstall using GUID:

Both examples, include the use to write to a log file “C:\msilogfile.log“, along with the necessary switches to uninstall and execute silently. (Above switches are lowercase)

Additional Information

Check the following links on:

1. Installing MSI files with PowerShell: https://kevinmarquette.github.io/2016-10-21-powershell-installing-msi-files/

2. Report or check any issues with PowerShell Core: https://github.com/PowerShell/PowerShell/issues

3. PowerShell Core Reach GA (Generally Available) status: https://blogs.msdn.microsoft.com/powershell/2018/01/10/powershell-core-6-0-generally-available-ga-and-supported/

Be Bold!! Learn PowerShell Core!!