• Design a script using PowerShell

    Home » Forums » Developers, developers, developers » DevOps Lounge » Design a script using PowerShell

    Author
    Topic
    #487216

    How to design a script (or someone has one) that could start and stop services, saved as a file and run by double-clicking its icon.

    Thanks

    Viewing 2 reply threads
    Author
    Replies
    • #1367574

      Given a bit more information about what you actually want to do, this could be as short as a one-line BATch file! (I don’t do PowerShell…)

      BATcher

      Plethora means a lot to me.

      • #1367607

        Hi BATcher,
        In Windows 7 System Conmfiguration/Services, there are a number of services such as
        ApplicationEXperience/Application Identity/Windows Audio/ActiveX Installer/computer Browser
        and the list goes on.

        I would like to stop a number of these services to relieve the load on the processor. I can do it
        manually by using the System Configuration panel.

        I would like to automate the stopping of a certain of these services by clicking an icon.

        Thanks

    • #1367614

      I would suggest you are not going to get the result you require, because an idle service imposes almost zero load on the processor.

      But if you want to go ahead…

        [*]Make a BATch file consisting of lines like

      SC STOP servicename1
      SC STOP servicename2
      and so on

        [*]Put it in a folder with a name like StopServ.bat
        [*]Use My Computer or Windows Explorer, and right-click on StopServ.bat, and select Send to -> Desktop (create shortcut)

      You now have a Stop Service icon on the desktop on which you can click.

      Do the same to create a StartServ.bat file, but of course using
      SC START servicename1
      and so on

      To find the correct service names for the services you want to stop or start, do something like
      SC QUERY > ListOfServices.txt
      and inspect the resulting (large!) file with something like NOTEPAD.

      For each service you will find

        [*]a service name (for example wuauserv)
        [*]a display name (for example Windows Update)

      You can use either of these where I have put servicename1, servicename2, etc, above – but make sure that the display name is in double-quotes, example
      SC STOP wuauserv
      or
      SC STOP “Windows Update”

      (Don’t actually STOP Windows Update – it is just an example!)

      Undoubtedly for each desktop icon you will need to go into its Properties, select the Shortcut tab, click on the Advanced button, and put a tick in the box in front of Run as Administrator.

      I hope that will enable you to do what you want.

      BATcher

      Plethora means a lot to me.

      • #1367811

        Thank you and I will try it out after figuring out the procedure to create batch file.

        • #1368857

          Thank you and I will try it out after figuring out the procedure to create batch file.

          To create a batch file, open Notepad, write the script and then save thusly:

          Select as file type as all files, not as .txt. (from the dropdown menu at the bottom of the save dialogue box)
          Name the file and give it the file extension .bat for example myscript.bat

          Now when you double this bat file, assuming your script is good, it will run…

    • #1368867

      I’ve been using this ‘Command Line Crash Course’ to learn quickly learn commands in Windows Power Shell and I really like it. Maybe you might enjoy it too: http://cli.learncodethehardway.org/book/

    Viewing 2 reply threads
    Reply To: Design a script using PowerShell

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: