currently I am trying to write a script that obtains a list of all services on my computer, then try to use each service name in that output to run "sc.exe qfailure [service]."
However, I am not sure why my output consistently runs a single service's name over and over again. Here is my code.
Also, I'm trying to make it that if any service is configured to run a program in it's recovery options, it should be able to print out the service name. I only know how to -match "RUN PROCESS" though. How can I match the service name?
Part of my code is below.
    $services = get-service | select -expand name;
    Write-Host $services
    $output = $services | ForEach {sc.exe qfailure $services in};
Will appreciate any help. Thanks so much!
When you pipe an object into foreach, each object within that object can be signified by the $_ variable
$output = $services | ForEach {sc.exe qfailure $_ in};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With