Syntax question from newbie

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Matt Bloomfield Matt Bloomfield 4 days, 12 hours ago.

  • Author
    Posts
  • #68908
    Profile photo of Richard Lyon
    Richard Lyon
    Participant

    Alright, I think I've figured it out, using the help files, but want confirmation. I'm looking at Stop-service, and its 3 parameter sets.

    NAME
    Stop-Service

    SYNOPSIS
    Stops one or more running services.

    SYNTAX
    Stop-Service [-InputObject] [-Exclude ] [-Force] [-Include ] [-PassThru]
    [-Confirm] [-WhatIf] []

    Stop-Service [-Exclude ] [-Force] [-Include ] [-PassThru] -DisplayName [-Confirm]
    [-WhatIf] []

    Stop-Service [-Name] [-Exclude ] [-Force] [-Include ] [-PassThru] [-Confirm]
    [-WhatIf] []

    -DisplayName
    Specifies the display names of the services to be stopped. Wildcards are permitted.

    Required? true
    Position? named
    Default value
    Accept pipeline input? false
    Accept wildcard characters? true

    -InputObject
    Specifies ServiceController objects representing the services to be stopped. Enter a variable that contains
    the objects, or type a command or expression that gets the objects.

    Required? true
    Position? 1
    Default value
    Accept pipeline input? true (ByValue)
    Accept wildcard characters? false

    -Name
    Specifies the service names of the services to be stopped. Wildcards are permitted.

    The parameter name is optional. You can use "Name" or its alias, "ServiceName", or you can omit the parameter
    name.

    Required? true
    Position? 1
    Default value
    Accept pipeline input? true (ByPropertyName, ByValue)
    Accept wildcard characters? true

    In particular, I was (am?) baffled by the second parameter set. I couldn't figure out how the service to be stopped was sent into it. But looking closely, I did notice the Displayname way down the parameter set. So, the reason its listed so far back from the beginning is that its named, not positional? And it would never be used as part of a pipeline... though I would imagine that a parenthesized get-service could be used in the parameter to supply it with some display names....

    Does all that even make sense? It seems like it would be the least used of the 3 parameter sets, off the top of my head.

  • #69109
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    I think the key here is that the neither the Exclude or the Include parameters accept pipeline input so if you pass a string representing the service's Display Name to Stop-Service the only parameter it can bind to will be DisplayName.

    If Exclude or Include accepted input from the pipeline then the DisplayName parameter would have to be in position 0.

You must be logged in to reply to this topic.