String not Passing to Get-Service

Maranya, Damon 326 Reputation points
2023-02-17T17:22:16.0033333+00:00

I'm trying to find which members of a list of device names in a file. don't have the wscsvc service running on them.

When I use a variable, I get a message saying "Get-Service : Cannot find any service with service name 'wscsv'.". If I replace the variable for the value that the variable contains, it retrieves the service status correctly. What am I missing?

$devices = Get-Content -Path '[File Path]'

foreach($device in $devices)
{

Get-Service -ComputerName $device -Name wscsvc | Export-Csv 'c:\temp\WSCSV_Status.csv'

}

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,874 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 47,766 Reputation points
    2023-02-17T20:15:47.42+00:00

    Are you trying to find the Windows Security Center Service? The name should be "wscsvc". The name in the error message is missing the letter "c" at the end of the name. Check the contents of the file containing the service names,

    0 comments No comments

  2. Maranya, Damon 326 Reputation points
    2023-02-21T15:32:06.8766667+00:00

    After some more tinkering this morning. It looks like some of devices on the list are present in AD, but don't have a DNS assignment for Get-Service to reference when trying to track down a device by its Device Name. Meaning that when it tries to find the device running the service, it can't locate it, and there for returns the "Can't find any service with the name 'wscsvc'" error.

    So, the script is working as it should. It's my expectations about the number of active devices that seems to be the problem here.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.