Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Powershell script for starting/stopping service is slow

$
0
0

So this is my first Powershell script; its purpose is to start and stop a service on remote machines.

param([String]$newStatus="Stopped", [String]$computersFilename="")
if ($computersFilename -eq "") {
    echo "no filename entered"
    exit
}
$computers = Get-Content $computersFilename
foreach ($i in $computers) {
	Get-Date 
	$i 
	$newStatus
	Set-Service -Computername $i -Name MyService -Status $newStatus
}

There are 23 computers on the list; this script takes about 7 minutes to run, sometimes a lot more. Any suggestions on getting it to run faster?

The script also hangs a few times until I press "Enter". In one instance, it hung for over an hour.

Also, I'm doing a test run on running this as a scheduled task, and it's hung... and I can't press enter because there's no window that it's running in.



Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>