$Server = Read-Host -Prompt 'Enter Server Name'
$Service= Read-Service- Prompt ' Enter Service"
while ($Server -ne "")
{
Get-Service -ComputerName $Server | Where Status -eq "Running" | Out-GridView
$Server = Read-Host -Prompt 'Enter Server Name'
$Service= Read-Service -Prompt 'Enter Service'
Restart-Service $Service -force
}
Is there a way to read the server name and to read the service then restart regardless of its status on the same network.for eg. if you have Mutiple computer and you required a service to be restarted on each of them.
Enter Server Name: ABC1
Enter Service: Service123
Service123 has been restarted successfully on Server ABC1 else Restart has failed please investigate
Have you tried to search for a solution or example code for tasks like this at first? That’s a very common and basic task. It is more than likely that you find some code snippets you can easily adapt to your particular needs.
And since you already posted some code … what’s wrong with it? What happend? What did not happen? Did you get some error messages? If yes why didn’t you post them?
IMHO it is always a bad idea to allow free text input for technical properties. A better solution would be to offer a predefined limited choise the user can choose from.
What is Read-Service? … but again … not a good idea to allow free text input for technical properties.