CodexBloom - Programming Q&A Platform

PowerShell 7.3 - implementing Retrieving Specific Service Status Based on Machine Name

👀 Views: 0 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-19
PowerShell remote services Windows

I need help solving I'm stuck on something that should probably be simple. I'm converting an old project and I'm working on a personal project and I'm trying to create a script that checks the status of specific Windows services on remote machines using PowerShell 7.3, but I'm working with unexpected behavior when filtering by machine name... My goal is to retrieve the status of the 'wuauserv' service on a list of machines defined in a CSV file. The CSV contains a column named 'MachineName'. Here's what I have: ```powershell $machines = Import-Csv -Path 'C:\Path\To\Machines.csv' $serviceName = 'wuauserv' foreach ($machine in $machines) { $service = Get-Service -Name $serviceName -ComputerName $machine.MachineName -ErrorAction Stop Write-Output "Service '$serviceName' on $($machine.MachineName) is $($service.Status)" } ``` However, I am getting the behavior: `Get-Service : want to find any service with service name 'wuauserv' on computer '<MachineName>'`. I've verified that the service exists on the remote machines and that I have the necessary permissions. To troubleshoot, I ran `Test-Connection` prior to this code to confirm that my script can reach the machines, which it can. I've also checked that WinRM is enabled and properly configured on the remote machines. Should I be using a different approach to ensure I can access the service status on these remote machines? Or is there something I might be missing in my current script? Any insights or alternative methods would be greatly appreciated! This is part of a larger CLI tool I'm building. Has anyone else encountered this? This is my first time working with Powershell LTS. Any advice would be much appreciated. This issue appeared after updating to Powershell 3.9. Any suggestions would be helpful. For reference, this is a production web app. Any help would be greatly appreciated!