Link to home
Start Free TrialLog in
Avatar of Kylo Ren
Kylo RenFlag for United States of America

asked on

powershell foreach-obj and get-services

Hi, how do i fix either one of these commands?  i get an error when i try to run it


get-service | foreach-object { if ($_.status -eq "stopped") {start-service $_}}

2nd variation

$service = get-service
get-service | foreach-object { if ($_.status -eq "stopped") {start-service $service}}
ASKER CERTIFIED SOLUTION
Avatar of KenMcF
KenMcF
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial