powershell run as different user elevated
Running a script from a script as a different user and elevated Initially i tried invoke-command however that bought up the âdouble hopâ authentication problem and i was reluctant to start setting credssp on machines not to mention i actually wanted to run it locally on the same server so the commands failed. After it runs I want to call this script again and run it as another user HOWEVER it has to be elevated to do so, before we always ran powershell as administrator on the second account. Tip: You can run an app elevated with the help of PowerShell directly without opening its console first. This is what I want to work. In Powershell >= 4.0 you can use requires statement at the top of your script to prevent a script from running as regular user: #Requires -RunAsAdministrator If the script is invoked from a non-elevated PowerShell process youâll receive the following error: Thatâs why you would first run an elevated cmd window and then use runas.exe to kick off the process with a different user. The reason for this is the User Account Control (UAC).Introduced with Windows Vista User Account Control (UAC) keeps the user in a non-elevated state if not explicitly told to be elevated as an administrator.. To read more about how the User ⦠For example, you can create a shortcut or type the following command in the Run dialog: powershell.exe -Command "Start-Process Notepad.exe -Verb RunAs" The result will be the same. I can right click on Powershell and run it as a different user, then paste the script there. Another way to easily access PowerShell is via the Win-X menu as shown in the following screenshot. the result should be your domain account, even when elevated. To run PowerShell, I had to use a slightly different ⦠Back to the Shortcut Properties, click OK to apply the changes and youâre all set. You canât just run PowerShell as a different user because ODBC requires PowerShell to be elevated. When a script is run with elevated permissions several aspects of the user environment will change: The current directory, the current TEMP folder and any mapped drives will be disconnected. This menu was never given an official name but was widely referred to as Win-X (or power user ⦠OR I usually just shift+right click > "launch as a different user" on either the script or on my powershell shortcut. But I need it to run as the second user so it can change those certain settings that are profile dependant. When using Powershell, you may need to run Powershell as an administrator to perform a specific task.. To add a "Run as Administrator" context menu for .ps1 files, run this from an elevated PowerShell ⦠Windows Explorer Context Menu. 6. Add-OdbcDsn wouldnât take credentials and the old command line dbdsn command is deprecated at this point. Quick note: If you click the arrow button, then you can select to launch the app as admin or as a different user. When I right click on the script, I am not given that option. Looking around the internet the consensus seemed to be that it wasnât possible. I needed to create the ODBC connection as a specific user. Iâve used batch files to run CMD, MMC, and other applications as a domain admin account in the past. I had a similar problem, I needed to test some backup code (PowerShell) which I needed to run as a different user account with elevated permissions due to the fact that the code updates registry keys on the local workstation where I was testing (which requires elevated permissions) but required access to SQL (which required to execute as a different ⦠If, like any sane sysadmin, you adhere to best practice and your own user account isnât a domain admin, youâre likely to be running certain operations as a domain admin. Introduction. Running PowerShell as Administrator Using WinX Menu. Shift+Right-click > Run as different user > Domain admin; Then do your runas to elevate from there (as the domain admin): Start-Process PowerShell -Verb RunAs You can check what user you're currently running as with whoami. So, running âas different userâ may solve your problem if you need to run a process as another user but this process is not necessarily elevated and therefore lacks the rights to alter your local system.