Please feel free to provide feedback or file bugs here.

Get-Service Name parameter allows Null value

Get-Service -Name $Null returns all services. Expected behavior would be for Name to have ValidateNotNullOrEmpty attribute assigned.

4 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Ben Gelens shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    3 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Ben Gelens commented  ·   ·  Flag as inappropriate

        Any parameter like Name or Id implies the expected result to be explicitly defined. No doubt unless wildcards are allowed.

        When you forget to assign a value or the value is Null by accident or a bug results in a Null value and it's used with Name, it will be Null and therefore return all services. Not everyone is using strictmode :-)

      • Roman Kuzmin commented  ·   ·  Flag as inappropriate

        > provide some data on what kind of scenario this might be impacting for you

        In theory, here is a possible unwanted scenario:

        $service = Get-ServiceToStop ...
        Get-Service $service | Stop-Service

        If Get-ServiceToStop is expected to get something but returns nothing then all services are going to be stopped.

      • Roman Kuzmin commented  ·   ·  Flag as inappropriate

        Agree.

        Get-Alias -Name $null -- also returns all items, it's not quite right.

        Get-Process, Get-Variable fail -- good.

      Feedback and Knowledge Base