0

Its very basic Here is what I am trying to accomplish:

#Make a list of programs depending on Input

get-service  | Where-Object {$_.name -Like $Input}| select-object name,  DisplayName, ServiceType, Status

get-service  | Where-Object {$_.name -Like "Sys*"}| select-object name, DisplayName, ServiceType, Status

Now the second get-service works no problem. But the first one does not cooperate with me, it just throws all the services on the server.

I obtain the user input with this:

$Input = Read-Host -Prompt 'Input your regex'

So what is going on here. Where have I gone wrong? And no, I test the variable with a write-host, the string is there. Its not disappearing as far as I can tell.

Jason091
  • 11
  • 1
  • 3

1 Answers1

0

The problem is simple due to scope.

The solution is to create a filter like shown here:

Why doesn't PowerShell Where-Object work when passing a variable?

I just did this:

#Make a list of programs depending on Input
$Filter = $Input
get-service  | Where-Object {$_.name -Like $Filter}| select-object name, DisplayName, ServiceType, Status
Community
  • 1
  • 1
Jason091
  • 11
  • 1
  • 3