Repository navigation
Open
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
Description
Summary of the new feature / enhancement
I want to be able to restart sshd from Windows and Linux in the same way after modifying sshd_config. This is almost possible, because Get-Content and Set-Content are already cross-platform. However, I currently must interact with the init-system when restarting services on Linux, despite an abstraction for net and sc (Restart-Service) already existing in PowerShell, and the potential solution being, I expect, so easy.
Attempt
-
#!/usr/bin/env pwsh Restart-Service 'sshd'
-
However, this produced:
Restart-Service: The term 'Restart-Service' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Proposed technical implementation details (optional)
Call systemctl restart sshd, if Get-Command systemctl returns True:
-
#!/usr/bin/env pwsh systemctl start 'sshd' && ` journalctl -fexu 'sshd'
-
Dec 28 18:29:10 beedell.rokejulianlockhart.1669806072 systemd[1]: Starting sshd.service - OpenSSH server daemon... ░░ Subject: A start job for unit sshd.service has begun execution ░░ Defined-By: systemd ░░ A start job for unit sshd.service has begun execution. ░░ The job identifier is 322. Dec 28 18:29:10 beedell.rokejulianlockhart.1669806072 sshd[1412]: Server listening on 0.0.0.0 port 22. Dec 28 18:29:10 beedell.rokejulianlockhart.1669806072 sshd[1412]: Server listening on :: port 22.
Footnotes
Reacted by Mr Beedell, Roke Julian Lockhart, cachius and soroshsabz
Metadata
Metadata
Assignees
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
Activity
rhubarb-geek-nz commentedon Feb 4, 2023
It may be simple solution for this single case but it raises a whole new set of expectations that PowerShell will provide systems management functions on all platforms equivalent to what it does on windows.
I would suggest a better solution would be to have new GitHub projects that implements the equivalent missing cmdlets for different platforms much like PowerShell/ThreadJob is a separate project. Given the platforms that PowerShell supports as a scripting language, that would imply there need to be equivalents for Linux as well as macOS, and for Linux for systemd, openrc or traditional init systems.
SteveL-MSFT commentedon Aug 2, 2023
The @PowerShell/wg-powershell-cmdlets discussed this. We agreed that there is existing precedent to provide cmdlet abstraction over Unix commands (see Restart-Computer as an example).
In this case, we recommend a fallback system to search for common commands used by various distros (including macOS) to restart a service on those platforms and if no common command is found then fail the entire operation,. We also suggest looking if
sudoexists and using that to avoid the inevitable permission problem assudocannot elevate cmdlets. Check the exit code and if non-zero, emit STDERR as an ErrorRecord.We would expect
Get-Service,Stop-ServiceandStart-Serviceto also use the same/similar code.For capability beyond what is provided by the existing cmdlet, we would recommend as a separate module published to PowerShellGallery.
beedell-roke commentedon Jan 30, 2024
[-]Restart-Service should call systemctl restart on systemd-present Linux distributions.[/-][+]`Restart-Service` should call `systemctl restart` on Linux OSes with SystemD present.[/+]beedell-roke commentedon Jul 31, 2024
beedell-roke commentedon Jan 28, 2025
cachius commentedon Aug 4, 2025
Steve Lee (@SteveL-MSFT) The commands would be
For Linux/systemd
systemctl restartStop and then start one or more units specified on the command line. If the units are not running yet, they will be started.For macOS
launchctl kickstart -kIf the service is already running, kill the running instance before restarting the service.If going the way of Restart-Computer. One could also do a minimal cross-platform ServiceController. Maybe leaned on CIM.
beedell-roke commentedon Feb 1, 2026
beedell-roke commentedon Aug 2, 2026