Cannot work with get-service bind parameter

I am learning PowerShell and asking a question about parameter binding. This is probably a simple question, but I'm at a loss.

If I print:

get-adcomputer -filter 'name -eq "serverone"' |
  select @{name='computername';e={$_.name}} |
  get-process

which gives me a list of processes on "serverone" and works fine. But if I print:

get-adcomputer -filter 'name -eq "serverone"' |
  select @{name='computername';e={$_.name}} |
  get-service

then I get the following error:

get-service : Cannot find any service with service name
'@{computername=SERVERONE}'. At line:1 char:93
+ ... e={$_.name}} | get-service
+                    ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (@{computername=SERVERONE}:String) [Get-Service], ServiceCommandException
    + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand

Why is this? Both Get-Processand Get-Servicetake computer name, and help files for this parameter look the same. Interestingly, if I type the same code, but add -Name bitsto the command Get-Serviceabove, it returns with the service data. So it looks like it is Get-Servicetrying to associate an object with a service name, but this does not happen with Get-Process, which looks very similar in syntax ?!

+4
source share
2

Get-Service - , , , -Name. Name, , @{computername=SERVERONE}. Get-Service , , , , , .

Get-Service ( ):

PS C:\> Get-Help Get-Service -Parameter Name

-Name 
    Specifies the service names of services to be retrieved. Wildcards
    are permitted. By default, Get-Service gets all of the services on
    the computer.

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

PS C:\> Get-Help Get-Service -Parameter ComputerName

-ComputerName 
    Gets the services running on the specified computers. The default
    is the local computer.

    Type the NetBIOS name, an IP address, or a fully qualified domain
    name of a remote computer. To specify the local computer, type the
    computer name, a dot (.), or "localhost".

    This parameter does not rely on Windows PowerShell remoting. You
    can use the ComputerName parameter of Get-Service even if your
    computer is not configured to run remote commands.

    Required?                    false
    Position?                    named
    Default value                Local computer
    Accept pipeline input?       true (ByPropertyName)
    Accept wildcard characters?  false

Get-Process ( ):

PS C:\> Get-Help Get-Process -Parameter Name

-Name 
    Specifies one or more processes by process name. You can type
    multiple process names (separated by commas) and use wildcard
    characters. The parameter name ("Name") is optional.

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

PS C:\> Get-Help Get-Process -Parameter ComputerName

-ComputerName 
    Gets the processes running on the specified computers. The default
    is the local computer.

    Type the NetBIOS name, an IP address, or a fully qualified domain
    name of one or more computers. To specify the local computer, type
    the computer name, a dot (.), or "localhost".

    This parameter does not rely on Windows PowerShell remoting. You
    can use the ComputerName parameter of Get-Process even if your
    computer is not configured to run remote commands.

    Required?                    false
    Position?                    named
    Default value                Local computer
    Accept pipeline input?       true (ByPropertyName)
    Accept wildcard characters?  false

, -Name . Get-Service -Name , , Get-Process - . Get-Process , Get-Service .

, , . * . -Name -ComputerName :

Get-ADComputer -Filter 'Name -eq "serverone"' |
  select @{n='ComputerName';e={$_.Name}} |
  Get-Service -Name *
+5

(1 ).

Get-Service 3: Default, DisplayName InputObject.

, , , PowerShell -.

:

  • InputObject: ServiceController, .
  • DisplayName. , , , :

1 |
select @{l='computername';e={$env:COMPUTERNAME}} |
gsv -DisplayName 'your-service's-display-name'

  • . , , , . _ , . :

1- :

1 |
select @{l='computername';e={$env:COMPUTERNAME}} |
gsv alg # 'alg' is the service name; you can choose some other(s)

2- :

1 |
select @{l='name';e={'alg'}},@{l='computername';e={$env:COMPUTERNAME}} |
gsv

, . , ( _), .

0

All Articles