0

I have a big PowerShell script that I want to run for each user automatically. I want to run this command as Admin and not have to specify credentials of other Standard users because all Standard users are Microsoft password-less accounts using Windows Hello authentication.

so far I managed to do this but it doesn't work for all users, only runs the script as Admin, which is the user that the PowerShell instances is running under.

$usernames = Get-LocalUser | ?{$_.enabled -EQ "True"} | select "Name"

$usernames | foreach { $bigscript }

$bigscript = 

I read other guides but they all required me to specify credentials, but I don't have credentials. how can I do this?

I'm using latest version of Windows 11

  • What is the purpose of running it "for each user"? What does the script do? Is impersonating the target accounts necessary, or do you just need access to, say, their profile folder on disk? – Mathias R. Jessen Oct 17 '22 at 10:28
  • My script mostly runs tasks that need admin access, but some of the commands only apply to the current user, like those that are related to personalization, that's why I need to run my script for each user individually so that Admin can perform commands that require Admin access and when it's run as standard users, those commands will be ignored and the rest that apply to the current user will be applied. –  Oct 17 '22 at 10:31

0 Answers0