WINDOWS: Elevating PowerShell to Admin Mode without UAC prompt

A Tech Lead by profession, a Data Enthusiast and a forever learner. Experienced in DevOps, Cloud, FullStack Development, Data Science, Machine Learning and AI.
Search for a command to run...

A Tech Lead by profession, a Data Enthusiast and a forever learner. Experienced in DevOps, Cloud, FullStack Development, Data Science, Machine Learning and AI.
No comments yet. Be the first to comment.
Hashnode introduced 'headless' and while having a look at it, It really seemed interesting. It's nice to have a way to play with our publications and posts from Hashnode, outside of Hashnode without tedious data scraping. While reading another blog, ...

While trying to get Red Hat (RHEL9) installed in my WSL (Windows Subsystem for Linux) within my Windows 11 laptop, I stumbled upon the same hurdle I did for installing the older RHEL8. The list of available distros published by Microsoft still does n...

When it comes to collaborative software development, efficiency in communication and planning are critical. GitHub offers a feature called "Code owners" to improve project management and facilitate cooperation. Let's see how this can improve your dev...

While trying to setup RHEL with WSL 2, I stumbled upon this very helpful blog https://wsl.dev/mobyrhel8/ While doing the setup, I found this zsh theme very nice, and I have been using it since then. The above mentioned blog already has the steps, but...

PowerShell is a powerful tool, allowing to perform a myriad of tasks with just a few commands. However, there are times when elevated privileges are required to execute certain commands. This is as easy as right-clicking PowerShell and "Run As Administrator" 👎. Not as easy though when you want to launch it entirely from the terminal, without any GUI popup (UAC).
Microsoft provides a not so beautiful but powerful command to do that too. Drumrolls......
The `runas` command in Windows allows users to run a program with different user credentials than the ones currently in use. To open PowerShell in administrator mode with a domain admin user, the following command can be used:
runas /user:DOMAIN\adminuser "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command \"Start-Process powershell -ArgumentList '-NoProfile -NoExit' -Verb RunAs\""
NOTE: Remember to replace placeholders like "DOMAIN" and "adminuser" with your actual domain name and admin username.
This command will give a command line prompt to enter password.
This command utilizes the `-NoExit` parameter, ensuring that the PowerShell console remains open after execution.
- runas /user:DOMAIN\adminuser: Specifies the domain and admin user for which elevated privileges are required.
- powershell.exe -NoProfile -ExecutionPolicy Bypass: Launches PowerShell with specific settings. The `-NoProfile` flag ensures a minimal profile is used, and `-ExecutionPolicy Bypass` allows the execution of scripts.
- Start-Process powershell: Initiates a new PowerShell process.
- -ArgumentList '-NoProfile -NoExit': Passes additional arguments to the new PowerShell process. The `-NoExit` parameter prevents the console from closing immediately.
- -Verb RunAs: Requests to run the process with elevated permissions.
- Script Execution: Running scripts that require administrative privileges.
- System Configurations: Making changes to system settings that necessitate elevated access.
- Software Installations: Installing software that requires administrative rights.