PowerShell script to restart the service

My task is to press a key sequence, such as Ctrl + Shift + R , to restart the Windows service.

I have a script that works fine in PowerShell ISE when run as administrator.

When I try to use the PowerShell script, it does not work due to insufficient administrative privileges. It's annoying that I can get it to work with the old bat file, but not with PowerShell.

The root of the problem is that the shortcuts for the PowerShell script have a grayed out Administrative Privileges window. So far, no work has overcome this privilege problem.

Any ideas?

+4
source share
2 answers

One approach is to start another PowerShell session in your script like this:

Start-Process PowerShell.exe -arg '-nologo -noprofile script.ps1' -verb runas 

This should encourage you to pick up a new PowerShell session. I think you should set the -WindowStyle parameter so that a new window does not appear (if you need this behavior). Please note that you will need to specify the full path to the existing script.

+2
source

You suggest you don’t like to solve this problem with a batch file (for example, net start), I think because batch files are by nature more limited than powershell scripts. What you can do is wrap your Ps script in a batch file, although in order to achieve your goal, run the powershell script using the keyboard shortcut without any access rights issues. Try this in a batch file:

  powershell set-executionpolicy remotesigned powershell myscript.ps1 
0
source

Source: https://habr.com/ru/post/1309789/


All Articles