Skip to content

Document Unix platform support for Get/Start/Stop/Restart-Service #13385

Open

Description

@soroshsabz

Prerequisites

  • Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
  • Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Document new Get-Foo cmdlet" instead of "New cmdlet."

Summary

PowerShell is adding Unix platform support for the Get-Service, Start-Service, Stop-Service, and Restart-Service cmdlets in PowerShell 7.8. The cmdlet references currently document these cmdlets as Windows-only; they need to describe the new Unix behavior, the returned UnixServiceController object, and the sudo requirements for service management.

Details

The change was proposed in PowerShell/PowerShell#18863 and is implemented in PowerShell/PowerShell#28385 (targeting master, so the feature ships in PowerShell 7.8 - it is not part of the released PowerShell 7.7): on Linux and macOS, the four service cmdlets work through the system service manager, which is discovered in this order: systemctl (systemd), launchctl (macOS), service (sysvinit), and rc-service (OpenRC).

On Unix platforms:

  • The cmdlets return UnixServiceController objects instead of System.ServiceProcess.ServiceController objects. The Status and StartType properties map the service manager state onto the same enumerations that are used on Windows.
  • Getting service information doesn't require elevated permissions. The service management cmdlets require root privileges; when they aren't running as root, they wrap the service manager command with sudo -n and write a non-terminating error when elevation isn't available.
  • The DependentServices and RequiredServices parameters are only populated by systemd.
  • The Force parameter is accepted for script compatibility but has no effect on Unix.
  • The remaining service cmdlets (Set-Service, New-Service, Remove-Service, Suspend-Service, and Resume-Service) stay Windows-only.

Articles

The reference updates target the reference/7.8 version folder, which is created upstream when the PowerShell 7.8 preview documentation cycle begins:

  • Get-Service (reference/7.8/Microsoft.PowerShell.Management/Get-Service.md)
  • Start-Service (reference/7.8/Microsoft.PowerShell.Management/Start-Service.md)
  • Stop-Service (reference/7.8/Microsoft.PowerShell.Management/Stop-Service.md)
  • Restart-Service (reference/7.8/Microsoft.PowerShell.Management/Restart-Service.md)

Conceptual updates that don't depend on the version folder are already in progress:

Suggested updates:

  1. Remove the "This cmdlet is only available on the Windows platform." callouts and the Windows-only availability notes from the four reference pages in reference/7.8.
  2. Document the Unix service manager discovery order, the UnixServiceController output object, the sudo requirements, and the per-parameter platform behavior in the DESCRIPTION, PARAMETERS, OUTPUTS, and NOTES sections.
  3. Annotate the four service cmdlets as available for Linux and macOS in PowerShell 7.8+ in the conceptual articles (done in Document Unix platform support for Get/Start/Stop/Restart-Service (PowerShell 7.8) #13383).

Suggested content

Unix support note for each cmdlet's DESCRIPTION section:

Beginning in PowerShell 7.8, this cmdlet is also available on Linux and macOS. On Unix platforms the cmdlet works through the system service manager, which it discovers in this order: systemctl (systemd), launchctl (macOS), service (sysvinit), and rc-service (OpenRC). For more information, see the Notes section.

Unix output object section:

Microsoft.PowerShell.Commands.UnixServiceController

On Unix platforms, this cmdlet returns UnixServiceController objects that represent the services reported by the system service manager.

Related Source Pull Requests

Related Source Issues

Activity

  1. riju568 commented on Nov 16, 2026

    @riju568

    If you want to bump up the issue and related PR (#13383), mention particular "gotcha" scenarios in the Unix service management that the Power Shell user community might be confused by (e.g., sudo -n, scope of launchctl, etc.).
    Awesome write-up! PR #13383 is already in this branch, so I'll review the change there. Just a few quick edge cases I want to make sure are explicitly addressed in the NOTES section for anyone deploying to production:
    1). Non-interactive sudo -n behavior: Explain that since sudo -n is used when not running as root, in order for Start/Stop/Restart-Service to succeed in non-interactive scripts/CI pipelines on a remote machine without an intermediate prompt to elevate it- it needs a passwordless sudo (via NOPASSWD in /etc/sudoers), or a cached credential timestamp- or else it immediately errors out with a non-terminating error.
    2). MacOS (launchctl) domain scope: Indicate system-wide daemons (/Library/Launch Daemons, system domain) or user agents (gui/), since it depends on launchctl if pwsh is launched with sudo or not.
    3). Cross-references: Make it clear that the "Related Links" / NOTES in Set-Service, New-Service, Remove-Service, Suspend-Service and Resume-Service are specifically Windows-only so script migratees don't wrongly believe it's the whole noun group.

  2. soroshsabz commented on Nov 18, 2026

    @soroshsabz
    Author

    Thanks for the excellent review points - all three are now explicitly documented in PR #13383 (commit cba6695):

    1. Non-interactive sudo -n behavior - The Notes of Start-Service, Stop-Service, and Restart-Service now explain that sudo -n never prompts for a password, that the wrapped command succeeds only when the sudo credential timestamp is still cached (for example, shortly after running sudo -v in the same session) or when sudoers grants NOPASSWD for the service manager command, and that otherwise the cmdlet fails immediately with a non-terminating error instead of blocking on a prompt. They also state explicitly that non-interactive scripts and CI pipelines should either run pwsh as root (sudo pwsh) or configure passwordless sudo for the service manager command.

    2. macOS (launchctl) domain scope - The Notes of all four cmdlets now state that the domain depends on elevation: a root session manages/enumerates system-wide daemons installed in /Library/LaunchDaemons (the system domain), while a non-root session manages the current user's launch agents (the gui/<uid> domain), and that a non-root session can't manage system daemons or other users' agents. Get-Service additionally documents that its enumeration lists the matching domain.

    3. Windows-only cmdlets cross-reference - Each of the four cmdlets' Notes now ends with an explicit statement (as a > [!NOTE] callout in Stop-Service and Restart-Service) that Set-Service, New-Service, Remove-Service, Suspend-Service, and Resume-Service are only available on Windows platforms, so script migratees don't assume the whole noun group is cross-platform. Those five pages also keep their existing Windows-only callouts.

    Thanks also for the kind words about the write-up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions