PowerShell core on Linux - Get-Service should mimic linux "service" command.

Created on 17 Apr 2017  ·  3Comments  ·  Source: PowerShell/PowerShell

Steps to reproduce

Type the cmdlet: Get-Service ssh
Or, Stop-Service ssh
Or, Start-Service ssh

Expected behavior

PowerShell => Linux
Get-Service ssh => service --status-all
Start-Service ssh => service ssh start
Stop-Service ssh => service ssh stop

Actual behavior

Any of the three cmdlets will give the following errors:
xxx-service : The term 'xxx-service' is not recognized as the name of a cmdlet, function, script file, or operable
program.
xx-service_2017-04-17_13-59-44

Environment data

Linux Ubuntu Desktop 16.04.2

PS /home/maxt> $PSVersionTable                                                                                          
Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.18
CLRVersion
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Area-Cmdlets-Management Issue-Enhancement OS-Linux OS-macOS Up-for-Grabs

Most helpful comment

Hi any progress :-)

*-Service is probably the most important cmdlets to be ported to linux, Most my use of powershell is to create and manage services because it is so simple compared to sc, nssm.exe, sysinit and systemd.
Systemd is now used by most linuxes. I'm eagerly awaiting this.

Even Raspbian have systemd

# cat /proc/cpuinfo | grep model | head -1
model name      : ARMv7 Processor rev 5 (v7l)
# cat /etc/debian_version
9.1
# systemctl | grep service | wc -l
41
# pwsh
PowerShell 6.1.0
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /root> Get-Command | Measure-Object -line
Lines Words Characters Property
----- ----- ---------- --------
  323

PS /root> Get-Command | select-string -Pattern "Service"
PS /root>

All 3 comments

Except that service is only available on systemd machines. That's why this is tricky. We basically need to implement this behavior two (or three or four) times.

I agree as we start using powershell for managing azure deployments which may or may not be windows

Hi any progress :-)

*-Service is probably the most important cmdlets to be ported to linux, Most my use of powershell is to create and manage services because it is so simple compared to sc, nssm.exe, sysinit and systemd.
Systemd is now used by most linuxes. I'm eagerly awaiting this.

Even Raspbian have systemd

# cat /proc/cpuinfo | grep model | head -1
model name      : ARMv7 Processor rev 5 (v7l)
# cat /etc/debian_version
9.1
# systemctl | grep service | wc -l
41
# pwsh
PowerShell 6.1.0
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /root> Get-Command | Measure-Object -line
Lines Words Characters Property
----- ----- ---------- --------
  323

PS /root> Get-Command | select-string -Pattern "Service"
PS /root>
Was this page helpful?
0 / 5 - 0 ratings