익명 01:51

How to run a PowerShell script at logon for all (current and future) users with ...

How to run a PowerShell script at logon for all (current and future) users with elevated permissions without UAC

I'm building a login script for our company. Some of the things it will do include installing printers, mapping drives, setting wallpapers, etc. Many of these things will require elevated permissions. Many of these things will also require the username (IE cannot be run as system, must have user context to check groups, etc).

I first looked at Intune/MEM (we are 100% M365/Azure, no on-prem servers). You can go to AzureAD > Devices > Scripts and apply a script, but my understanding is that this only runs once and then again if it is changed, not at every login as desired.

Second I tried shell:common startup. I quickly realized this would result in a UAC prompt at every login (making registry changes, etc). No go.

Then I tried a scheduled task. This works well as you can run it as the user with "highest privileges" toggle. The problem I ran into here is that you have to create the task under each user. I really need this to apply to all users as well as future users. IE, if a new user logs into a conference room PC I need it to run the script immediately.

So, that's where I stand. What are my options? Is there a way to create a system wide scheduled task that runs at login of every user under the user context? Am I missing something with Microsoft Endpoint Management that constitutes a proper login script? Group Policy? I think the startup folder is completely out, but open to options here too (do not want to disable UAC though).



Top Answer/Comment:

There exist software products that allow running specific commands in elevated/administrator mode.

Example products (more may exist):

  • Steel Run As (commercial)
    Uses the administrator account while hiding the administrator password that is required for making it work.

  • NirSoft AdvancedRun (free)
    A more elaborate RunAs program.

Another solution might be to use the Task Scheduler to schedule running a script as administrator, but with a trigger that is never activated, and to run it with the command :

schtasks /run /tn "task-name"

For more information see the article
Windows 7: Elevated Program Shortcut without UAC Prompt - Create.

상단 광고의 [X] 버튼을 누르면 내용이 보입니다