Run powershell script without admin priv.

Daniel Kaliel 1,346 Reputation points
2023-06-07T21:19:49.22+00:00

I have a little script that users can run that restarts a few services and cleans temp files. Which works because they are administrators on their own PCs. That's changing, however, and the script will fail because Users don't have enough privilege to restart services.

The only solution I can think of is to have a scheduled task that is set to run as System with elevated priv, and what the user does instead is start the task. Is there another, more elegant, way to do this?

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2023-06-08T01:12:56.81+00:00

    Hi @Daniel Kaliel ,

    if the user doesn't have the privileges/permission to restart the service as a non-admin user you have 2 options:

    Use a task with a privileged user like you described.

    Assign the required privileges to the "non-admin" user -> How to Allow Non-Admin Users to Start/Stop Windows Service?


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.