Enable services from list

hi guys, i have the following script but id like to run on multiple machines at the same time. if i have a txt file is it possible to import the machine names and run the command on each

$svc = Get-Service -Name MSExchangePop3 -ComputerName server1
start-Service -InputObject $svc
LVL 15
cwstad2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
store computer names in c:\computers.txt

Get-Content C:\computers.txt | ForEach-Object { Start-Service -InputObject $(Get-Service -Name MSExchangePop3 -ComputerName server1) }
0
YZlatCommented:
$Servers = Get-Content C:\ServerList.txt


foreach ( $Server1 in Servers ) {
       $svc = Get-Service -Name MSExchangePop3 -ComputerName $Server1
start-Service -InputObject $svc 
        
}

Open in new window

0
YZlatCommented:
marahman, in your code you didn't specify the computer name. try using $_ instead of server1
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Oops! Forgot to change the servername

Slight change and New code should be
----------------------------------------------------
store computer names in c:\computers.txt

Get-Content C:\computers.txt | ForEach-Object { Start-Service -InputObject $(Get-Service -Name MSExchangePop3 -ComputerName $_) }
0
cwstad2Author Commented:
Hi guys, YZlat im getting this error

Servers : The term 'Servers' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a p
ath was included, verify that the path is correct and try again.
At line:4 char:23
+ foreach ( $Server1 in Servers ) {
+                       ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Servers:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
placing $ in front of Servers  will work (in YZlat code)
The code which I sent does also work. its the same functionality.
0
cwstad2Author Commented:
i tried that
0
YZlatCommented:
Oops, you need a $ sign in front of Servers - $Servers

$Servers = Get-Content C:\ServerList.txt


foreach ( $Server1 in $Servers ) {
       $svc = Get-Service -Name MSExchangePop3 -ComputerName $Server1
start-Service -InputObject $svc 
        
} 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cwstad2Author Commented:
thanks the problem was with the txt document.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.