How to run powershell on Linux

Mr. Sonnie Ardhianto
2 min readNov 12, 2024

--

Background
[Last updated date: 20-Nov-24]
Running powershell in terminal session somehow is automatically killed after sometime.
So we need to run powershell (still in terminal) but using “screen” or “tmux”.

This article was written on 12-Nov-24.
I need to run remote powershell job but I do not want to use Windows client (10 or 11) as they are single user only — which means I have to login all the time and preventing other users to use it.
So, Linux system is my better option and here is how I setup powershell on my Debian based linux.

Precautions
There is no precaution as Linux is durable, it won’t break.

Prerequisites
You need to have a running linux system (I am using Debian 12).
Of course a linux user with sudo privilege.
And windows system in which you want to run your remote powershell job.

Installation
You can get powershell module from Microsoft:
https://learn.microsoft.com/en-us/powershell/scripting/install/install-debian

Yet obviously you won’t be using powershell in linux, and you want to run remote powershell job.

For that, you need to install WSMan.

Install the PSWSMan module:

pwsh -Command "Install-Module -Name PSWSMan -Force"

Install the WSMan client:

pwsh -Command "Install-WSMan"

And we need to install additional linux library ntlmssp

sudo apt-get install -y gss-ntlmssp

To allow longer (permanent) terminal session, install “screen” or “tmux” you can use below command:

sudo apt-get install screen,tmux

Running powershell on Linux
Okay, now we are ready to run our remote powershell job from linux.

Using terminal, first you create your screen or tmux session. I am using screen and below is the command:

screen -S mypwshsession

To run powershell in linux, type “pwsh”

pwsh
Running powershell in Linux console

Example script is as below:

$computers = @("winsys1","winsys2")
Invoke-Command -ComputerName $computers -Credential Get-Credential -Authentication Negotiate -ScriptBlock { & "yourscript" } -AsJob

This script will prompt for credential to access remote windows system and run your script.

Once your powershell script is running in remote windows system, you can disconnect from your screen using:

CTRL+A, D

Linux “Screen” Management
To see list of running screens:

screen -ls

To reconnect to an existing screen

screen -r mypwshsession

To close an existing screen you can always use “exit” once you are inside.
But if you want to exit remotely you can issue below command:

screen -X -S session_ID_or_name quit

Good luck with running your remote powershell job from Linux!

--

--

Mr. Sonnie Ardhianto
Mr. Sonnie Ardhianto

Written by Mr. Sonnie Ardhianto

A stoned monkey randomly typing on keyboard

No responses yet