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;








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!










share|improve this question






























    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!










    share|improve this question


























      0












      0








      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!










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 3:45









      3377 Hutt3377 Hutt

      1




      1

























          1 Answer
          1






          active

          oldest

          votes


















          0














          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






          share|improve this answer
























            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
            );



            );













            draft saved

            draft discarded


















            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









            0














            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






            share|improve this answer





























              0














              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






              share|improve this answer



























                0












                0








                0







                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






                share|improve this answer













                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







                share|improve this answer












                share|improve this answer



                share|improve this answer










                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





















                    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.



















                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript