In Powershell, is there a way to stop a service, specify a wait time, and then have that service restart?Is there a way to get Powershell 5's Get-Help to parse the current script?Powershell: waiting for changed directoryAdd header row to .csvpowershell wait for command to finish before proceedingIs there a way to enable “noninteractive” from within a powershell sessionHow to create working Powershell task to stop process hung Firefox process?How to stop Powershell from flattening parameter of jagged array?How to kill a process at specific time and restart it after x minutes?Reloading a Powershell Class Module Without Restarting the Shell?How to stop Get-Content -wait after I find a particular line in the text file using powershell?
…down the primrose path
Getting Lost in the Caves of Chaos
Repeated! Factorials!
Why private jets such as GulfStream ones fly higher than other civil jets?
Can you take actions after being healed at 0hp?
What is an air conditioner compressor hard start kit and how does it work?
Did Captain America make out with his niece?
split large formula in align
Can a Hogwarts student refuse the Sorting Hat's decision?
Which genus do I use for neutral expressions in German?
I am considering a visit to a Nevada brothel. What should I say at the US border?
Non-small objects in categories
Changing Row Keys into Normal Rows
Our group keeps dying during the Lost Mine of Phandelver campaign. What are we doing wrong?
Is space radiation a risk for space film photography, and how is this prevented?
Write The Shortest Program To Check If A Binary Tree Is Balanced
London underground zone 1-2 train ticket
How to call made-up data?
Premier League simulation
Probably terminated or laid off soon; confront or not?
I was contacted by a private bank overseas to get my inheritance
Is a switch from R to Python worth it?
Make a living as a math programming freelancer?
Why is Chromosome 1 called Chromosome 1?
In Powershell, is there a way to stop a service, specify a wait time, and then have that service restart?
Is there a way to get Powershell 5's Get-Help to parse the current script?Powershell: waiting for changed directoryAdd header row to .csvpowershell wait for command to finish before proceedingIs there a way to enable “noninteractive” from within a powershell sessionHow to create working Powershell task to stop process hung Firefox process?How to stop Powershell from flattening parameter of jagged array?How to kill a process at specific time and restart it after x minutes?Reloading a Powershell Class Module Without Restarting the Shell?How to stop Get-Content -wait after I find a particular line in the text file using powershell?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to create a script that will get a service, stop it, and wait 60 seconds before restarting the service. What Cmdlets would I be incorporating?
I've tried utilizing the "Restart-Service" cmdlet, since the help description claims it is designed to start and restart a given service, but none of the associated parameters offer a way to set a specified time before restarting the service.
Any suggestions would be appreciated. Thanks!
powershell-5.0
add a comment |
I need to create a script that will get a service, stop it, and wait 60 seconds before restarting the service. What Cmdlets would I be incorporating?
I've tried utilizing the "Restart-Service" cmdlet, since the help description claims it is designed to start and restart a given service, but none of the associated parameters offer a way to set a specified time before restarting the service.
Any suggestions would be appreciated. Thanks!
powershell-5.0
add a comment |
I need to create a script that will get a service, stop it, and wait 60 seconds before restarting the service. What Cmdlets would I be incorporating?
I've tried utilizing the "Restart-Service" cmdlet, since the help description claims it is designed to start and restart a given service, but none of the associated parameters offer a way to set a specified time before restarting the service.
Any suggestions would be appreciated. Thanks!
powershell-5.0
I need to create a script that will get a service, stop it, and wait 60 seconds before restarting the service. What Cmdlets would I be incorporating?
I've tried utilizing the "Restart-Service" cmdlet, since the help description claims it is designed to start and restart a given service, but none of the associated parameters offer a way to set a specified time before restarting the service.
Any suggestions would be appreciated. Thanks!
powershell-5.0
powershell-5.0
asked Mar 27 at 3:45
3377 Hutt3377 Hutt
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You could try something like this:
$serviceName="MyService";
$waitTime = New-TimeSpan -Minutes 1
$service = Get-Service -Name $serviceName
$service.Stop()
$service.WaitForStatus("Stopped", $waitTime)
$service.Start()
$service.WaitForStatus("Running", $waitTime)
You can query the service by display name if you would like also.
You have to check if the service is running otherwise stop will throw an exception
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369473%2fin-powershell-is-there-a-way-to-stop-a-service-specify-a-wait-time-and-then-h%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could try something like this:
$serviceName="MyService";
$waitTime = New-TimeSpan -Minutes 1
$service = Get-Service -Name $serviceName
$service.Stop()
$service.WaitForStatus("Stopped", $waitTime)
$service.Start()
$service.WaitForStatus("Running", $waitTime)
You can query the service by display name if you would like also.
You have to check if the service is running otherwise stop will throw an exception
add a comment |
You could try something like this:
$serviceName="MyService";
$waitTime = New-TimeSpan -Minutes 1
$service = Get-Service -Name $serviceName
$service.Stop()
$service.WaitForStatus("Stopped", $waitTime)
$service.Start()
$service.WaitForStatus("Running", $waitTime)
You can query the service by display name if you would like also.
You have to check if the service is running otherwise stop will throw an exception
add a comment |
You could try something like this:
$serviceName="MyService";
$waitTime = New-TimeSpan -Minutes 1
$service = Get-Service -Name $serviceName
$service.Stop()
$service.WaitForStatus("Stopped", $waitTime)
$service.Start()
$service.WaitForStatus("Running", $waitTime)
You can query the service by display name if you would like also.
You have to check if the service is running otherwise stop will throw an exception
You could try something like this:
$serviceName="MyService";
$waitTime = New-TimeSpan -Minutes 1
$service = Get-Service -Name $serviceName
$service.Stop()
$service.WaitForStatus("Stopped", $waitTime)
$service.Start()
$service.WaitForStatus("Running", $waitTime)
You can query the service by display name if you would like also.
You have to check if the service is running otherwise stop will throw an exception
answered Mar 27 at 5:24
Mihail StancescuMihail Stancescu
3,6601 gold badge11 silver badges19 bronze badges
3,6601 gold badge11 silver badges19 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369473%2fin-powershell-is-there-a-way-to-stop-a-service-specify-a-wait-time-and-then-h%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown