Opening up Windows Terminal with elevated privileges, from within Windows Terminal - windows-terminal
There are plenty of questions here which asks how to elevate priviliges from powershell, and almost all of them recommend this command:
Start-Process -Verb RunAs powershell.exe .....
(or pwsh.exe for Powershell Core)
And this works, it opens up a new Powershell window with elevated privileges, after having gone through a UAC block to verify access.
However, while I'm using Powershell, I'm doing it inside Windows Terminal, the new terminal application for Windows 10, and I would like to open a new instance of Windows Terminal with elevated privileges, not just a Powershell window.
So I tried these commands:
Start-Process -Verb RunAs wt
Start-Process -Verb RunAs wt.exe
Start-Process -Verb RunAs (Get-Command wt)
Start-Process -Verb RunAs "C:\Users\lasse\AppData\Local\Microsoft\WindowsApps\wt.exe"
They all fail with:
Start-Process: This command cannot be run due to the error: The file cannot be accessed by the system..
I'm assuming this has something to do with where the executable is located, within my profile, but if I right-click the Windows Terminal icon I have on my task bar and choose to run it as administrator, it opens up just fine. This is what I want to duplicate.
So is there a way for me to modify either the commands I tried above, or change some access setting that would make this work?
For my specific instance, I simply want to make it simpler to pop open an admin terminal, I don't need a way to elevate arbitrary commands, then I will happily use the commands I have already shown here.
Currently you cannot open an elevated wt.exe session from the command line without workarounds. Workarounds include using gsudo, Using Task Scheduler (I tested this one and it works but you need to use the full path to wt.exe and you can skip the shortcut creation step) OR if you are ok with a keyboard shortcut, the simplest way; using a keyboard shortcut to run Windows Terminal as Admin from the taskbar.
For your use case:
For my specific instance, I simply want to make it simpler to pop open
an admin terminal, I don't need a way to elevate arbitrary commands,
then I will happily use the commands I have already shown here.
The simplest approach will work:
Pin Windows Terminal as the first item on the task bar. Then hit Win+Ctrl+Shift+1 to open it as admin.
If you really must launch Windows Terminal from the command line from within Windows Terminal then create a task in the Task Scheduler:
Give the task a name, check 'Run with highest privileges'.
Choose the 'Actions' tab, click 'New', select 'Start a program' as the action. Put the full path to wt.exe in the 'Program/script field'. Click OK. Click OK again.
Click 'Conditions' tab, uncheck "Start the task only if the computer is on AC power".
Click 'Settings' tab, make sure "Allow task to be run on demand" is checked and uncheck "Stop the task if running for longer than".
Finally in your shell (Powershell), launch an elevated Windows Terminal session by running the command: schtasks /run /TN "TASK_NAME" where TASK_NAME is the name you gave the task in step 1.
Try this:
powershell "Start-Process -Verb RunAs cmd.exe '/c start wt.exe'"
Also check out these links:
WT.exe command line arguments:
https://learn.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=windows
Article about adding Open Windows Terminal Command Prompt to the context menu in Explorer (includes Admin):
https://dkcool.tailnet.net/2020/07/add-open-windows-terminal-command-prompt-to-the-explorer-context-menu-in-windows-10/
Article about adding Open Admin Command Prompt to the context menu in Explorer:
https://dkcool.tailnet.net/2019/05/add-open-admin-command-prompt-to-the-explorer-context-menu-in-windows-10/
Not a direct answer but another option if you have PowerToys is to:
Alt + Space, type Terminal,
Select Run as Administrator (or Ctrl + Shift + Enter)
You can install PowerToys using WinGet
With recent releases, this issue appears to be fixed. It works now, doing exactly as you originally tried and failed (Start-Process -verb RunAs wt). I would recommend trying again now with the latest releases (at least Windows Terminal, and perhaps PowerShell as well).
No need for workarounds anymore!!
Windows Terminal has a feature to automatically run as administrator in the preview; no need for workarounds now.
Pin to the Taskbar and hold Ctrl + Shift while left clicking on the Windows Terminal icon.
In my particular case I also need Windows Terminal opened as administrator all the time. This is what I did, run "where wt" to display the path where Windows Terminal application exe is located, it should be C:\Users\YOURUSER\AppData\Local\Microsoft\WindowsApps\wt.exe.
I created a shortcut to that file and checked "Run as administrator" in the advanced properties, then I just pinned it to start and voila. You can delete your temporary shortcut after that if you want.
You can create a shortcut to always run Windows Terminal as administrator using this powershell script:
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Windows Terminal.lnk")
$Shortcut.TargetPath = "$env:LOCALAPPDATA\Microsoft\WindowsApps\Microsoft.WindowsTerminal_8wekyb3d8bbwe\wt.exe"
$Shortcut.Save()
$bytes = [System.IO.File]::ReadAllBytes("$Home\Desktop\Windows Terminal.lnk")
$bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON
[System.IO.File]::WriteAllBytes("$Home\Desktop\Windows Terminal.lnk", $bytes)
You can just paste it and run it from Windows Powershell ISE, it will create a Windows Terminal.lnk file on your desktop. Whenever you double click on that shortcut Windows terminal will run as an admnnistrator
I know this answer does not fully match your question but given that also other answers were oriented in this way I hope this won't disturb the discussion.
I always need to run PowerShell as Administrator and I only want to use Windows Terminal, which given it's restrictions cannot be configured to run always as Administrator.
I hated the need to use shortcuts and other hacks I found being suggested online, so I think I found a better solution but you have to pay the cost of a 1/2 seconds at startup.
Locate your user profile (A profile is a Windows PowerShell ISE script that runs automatically when you start a new session) using _ $PROFILE
Edit profile with any preferred editor _ code $PROFILE
Adde the following code to the profile file and save it
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$host.ui.rawui.windowtitle="Bootstrapper"
Start-Process -Verb RunAs wt
} else {
$Processes = Get-Process | Where-Object {$_.mainWindowTitle -eq 'Bootstrapper' -and $_.name -eq 'WindowsTerminal'}
if($Processes.count -gt 0)
{
Stop-Process -Id $Processes[0].id
}
}
What the script do?
You can pin Windows Terminal icon to your application bar and when you click there WT will start as non elevated user, but the profile will understand if this is the case.
When you are not running as Administrator it will change the name of the window and start a new WT as administrator.
The new instance will also execute the profile file and if the instance is runinng as Administrator, it will look for the WT named Bootstrapper and kill it.
This proces takes between one and two seconds, I prefer this way other than right clicking on the icon.
It's likely you were just facing a Path issue. I know that the command examples you gave (e.g. Start-Process -verb RunAs wt) have worked for me for some time (as mentioned in #fialdrexs's answer).
Did you install Windows Terminal from a Github release or from the Store?
I currently have the following entry in my settings.json profiles list to add an elevated Windows Terminal to the drop down options:
{
// https://github.com/microsoft/terminal/issues/632#issuecomment-663686412
"name": "Windows Terminal (elevated)",
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -Command Start-Process -Verb RunAs \"shell:appsFolder\\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App\"",
"hidden": false,
"icon": "ms-appx:///Images/Square44x44Logo.targetsize-32.png"
}
The comment with the GitHub link should get you to where I originally found this information.
I find a away to workaround, just create a file bat with content
powershell Start-Process -Verb RunAs wt.exe
Save file yourfile.bat to folder you want.
Add path folder to System Environment.
Press WINDOW + R and type file bat name.
Currently this problem was fixed, but it ended up with a weird issue. Running wt.exe from Win+R, searching it on start menu, and starting itself from the terminal, show the same error message.
The application was unable to start correctly (0xc0000022). Click OK
to close the application.
However it works when executing wt via Command Prompt, PowerShell, and PowerShell Core.
So just a quick workaround answer, start PowerShell and run the command,
Start-Process -Verb RunAs wt.exe;
or the simpler
start -verb runas wt
Related
How to convert opened CMD to Administrator CMD?
I am trying to open a Command Prompt as administrator, (elevated), from a normal user privileged Command Prompt. I searched Google a lot, but cannot find a method to achieve it. Is there any CLI command, to open an Administrator: Command Prompt, from a normal Command Prompt? Thanks in advance!
I don't know the meaning or any other explanation for this command but, it works with all Windows Operating system's (Windows 7,8,8.1,10,11 - Tested). Run this command in your normal user privileged Command Prompt Which will open another Administrator: CMD window. powershell -Command "Start-Process cmd -Verb RunAs" I got this Command from Google while searching on the Internet. If anybody know the meaning of this command plz update (Edit) my Answer!
There is no such command. Cmd needs to be invoked with the credentials you want to use. So changing users like for example in Terminal on Ubuntu is not possible at the moment. You can open a new Terminal by using runas /user:(UserNameHere) CMD.exe
How to "open with" in a batch file
I have a windows powershell script that will be available on a server to my users. I don't want them to have to go out and find the PS script, right click and click "run with powershell" or do an "open with". The Windows (Win 7 at least) default program is notepad. I want to make a batch file to do this. I've tried: start "c:\myfile.ps1" powershell.exe and a few other variations, but all I've been able to do is either start powershell, or open my file in its default program, notepad. Any advice is appreciated! Thanks! Bonus question: If I run my batch file as administrator will it also run my PS script as administrator?
Simply use the -file argument for PowerShell.exe in your batch file: PowerShell.exe -file c:\MyFile.ps1 Additionally, some users may have their Execution Policy set to something that would restrict scripts from being executed, so you may want to do something like: PowerShell.exe -ExecutionPolicy Bypass -file c:\MyFile.ps1 If you would like to use start to launch it you can do so as Ansgar Wiechers noted by running: start "" PowerShell.exe -ExecutionPolicy Bypass -file c:\MyFile.ps1 Some notes regarding using start: By default it will launch PowerShell in a separate window, and continue to execute the rest of the batch file without waiting for the PowerShell window to close. If that is undesirable you have two options. You can specify /wait which will wait for the PowerShell window to close before continuing the batch file, or you can use the /B option will will not open a new window, and will execute PowerShell in the current console window. And finally, yes if your batch file is run under the Administrator context, PowerShell will be as well.
cmd / powershell: minimize all windows on your desktop except for current command prompt (console) or except for some particular window
well, I know how to minimize all open windows on the desktop from a batch file by using powershell method - MinimizeAll(): powershell -command "& { $x = New-Object -ComObject Shell.Application; $x.minimizeall() }" the problem is: this method minimizes everything including current cmd-console which should be in my case always visible to the user. now, to workaround this problem I use external nircmd.exe tool and this part of my .bat-file looks like this: :: change current command prompt window title title my-cmd-console :: minimize all open windows on the desktop with powershell command powershell -command "& { $x = New-Object -ComObject Shell.Application; $x.minimizeall() }" :: bring console back to the front with nircmd.exe command 'win activate [filter window by title]' nircmd.exe win activate title "my-cmd-console" what I don't like about this code is that there is much 'flashing' on the screen: at start, the console appears on the desktop, then it gets minimized with all other windows and then it's brought back on the desktop front again. so, the question is: how to make console appear on the desktop front and 'lock it', so that it never gets out of sight until the command line EXIT is reached. P.S. not sure, but maybe there is an alternative solution to 'minimize all except for particular window' problem without need to use external nircmd.exe tool. any ideas?
minimize all but the active window (toggling command): nircmd sendkeypress rwin+home
runas command in windows 7
I'm trying to run a batch file as admin. I found that I can use runas command which corresponds sudo command in Linux I think. I tried runas /noprofile /user:computername\adminuser "blah.bat start" But it gives an error, saying : Logon failure: user account restriction.. (msdos window doesn't allow me to copy anything) is there any way I can run this batch file as admin? Right click doesn't work because I can't include any parameters.
A workaround: You can create a shortcut to the batch file, add a parameter in the shortcut, then right-click to run the shortcut as admin.
Right-click the icon for the command-prompt and choose Run As Administrator. Then run you batch file from that window.
I believe that you can allow or disallow the RunAs command with the registry. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer "HideRunAsVerb"= 1 See Disabling the RunAs Command
How do I start PowerShell from Windows Explorer?
Is there a way to start PowerShell in a specific folder from Windows Explorer, e.g. to right-click in a folder and have an option like "Open PowerShell in this Folder"? It's really annoying to have to change directories to my project folder the first time I run MSBuild every day.
In Windows Explorer, just go to the Address Bar at the top (keyboard shortcuts: Alt+D or Ctrl+L) and type powershell or powershell_ise and press Enter. A PowerShell command window opens with the current directory.
Just to add in the reverse as a trick, at a PowerShell prompt you can do: ii . or start . to open a Windows Explorer window in your current directory.
If you're on Windows 8, or later, you can simply use the built-in File → "Open Windows PowerShell". Or Alt + F followed by R.
As an alternative to the answer above, which requires you to type the PowerShell command (powershell.exe) each time, you can create a context menu entry just like with the "Open command window here" context menu. There are three registry keys where these commands go. Each key controls the context menu of a different Windows Explorer object. The first one is the one you asked about: HKCR\Directory\Background\shell - This is the context menu for the Explorer window itself (that is, the context menu that is displayed when no item is selected, such as when right-clicking in an empty area of the window). HKCR\Directory\shell - This is the context menu of the folders in Windows Explorer. HKCR\Drive\shell - This is the context menu for the drive icons in the root of Windows Explorer. For each of these registry keys, you can add a subkey that will add an "Open PowerShell window here" command to the context menu, just as you have an "Open command window here" context menu. Here is a copy of my OpenPowerShellHere.reg file, which puts the command in the context menu of each of the Explorer objects, the window background, the folder, and the drive icon: Windows Registry Editor Version 5.00 ; ; Add context menu entry to Windows Explorer background ; [HKEY_CLASSES_ROOT\Directory\Background\shell\powershell] #="Open PowerShell window here" "NoWorkingDirectory"="" [HKEY_CLASSES_ROOT\Directory\Background\shell\powershell\command] #="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'" ; ; Add context menu entry to Windows Explorer folders ; [HKEY_CLASSES_ROOT\Directory\shell\powershell] #="Open PowerShell window here" "NoWorkingDirectory"="" [HKEY_CLASSES_ROOT\Directory\shell\powershell\command] #="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'" ; ; Add context menu entry to Windows Explorer drive icons ; [HKEY_CLASSES_ROOT\Drive\shell\powershell] #="Open PowerShell window here" "NoWorkingDirectory"="" [HKEY_CLASSES_ROOT\Drive\shell\powershell\command] #="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'" So, with your favorite text editor, open a new file named OpenPowerShellHere.reg. Copy the exact text of the code above, paste it into the new file, and save it. (I would have included a copy of the file, but I couldn't figure out if attachments were possible.) If you want to exclude the command from one of the entry, just comment out the appropriate section with semicolons. My comments show you each section. After you save the file, run it by double-clicking on it. When it asks, tell it to proceed. As soon as you run it, the context menu entries will show up! Here is my Explorer window context menu. I've highlighted the console and PowerShell commands. As you can see, you can also add a context menu entry to run an elevated command window, i.e., Run as Administrator. Note: Context menu entries are displayed alphabetically, based on their Registry keys. The key name for the elevated command shell is "runas", which is why it comes after the PowerShell entry. Note: If you have an explorer window open, you may need to close it and reopen it to get the changed to take effect. Note: In Windows 7, the HKCR\Directory\Shell does not work if you use the toolkit on the side of the explorer (ie. Clicking Documents under the Libraries header) you must navigate using Computer -> C: -> to -> Some -> Target -> Directory
You can download the inf file from here - Introducing PowerShell Prompt Here
In Windows 10 both the command prompt and the powershell prompt can be found via the menu bar, for both non-admin and admin. These options will have its folder set to the currently selected folder from the explorer. For the Swedish version at least, the powershell is opened with Alt F+I. For an administrator powershell it's Alt F+S+P. If those are not the correct characters you can press and hold the Alt key to see the correct characters. there will be a character overlaying the menu item for each step.
I'm surprised nobody has given this answer, it's the simplest one. (Must be the year.) Just Shift + right click in Explorer. Then you can "Open PowerShell window here". It may be set to Command Prompt by default. If so, you can change this in the Windows 10 Settings: go to Personalization -> Taskbar and enable "Replace Command Prompt with Windows PowerShell in the menu when I right-click the start button or press Windows key+X".
Windows 10 made it much easier. You can either: SHIFT + Mouse Right Click on a folder, and you get a menu item Open PowerShell window here. Or you can: File -> Open Windows PowerShell. And for a bonus ... If you Mouse Right Click on File -> Open Windows PowerShell, then you can Add to Quick Access Toolbar: Which puts a handy icon here: And now you can just click that icon. :)
I wanted to have this context menu work only when right clicking and holding the 'SHIFT' which is how the built in 'Open Command window here' context menu works. However none of the provided solutions did that so I had to roll my own .reg file - copy the below, save it as power-shell-here-on-shift.reg and double click on it. Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\powershell] #="Open PowerShell here" "NoWorkingDirectory"="" "Extended"="" [HKEY_CLASSES_ROOT\Directory\shell\powershell\command] #="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"
Try the PowerShell PowerToy... It adds a context menu item for Open PowerShell Here. Or you could create a shortcut that opens PowerShell with the Start In folder being your Projects folder.
In the more recent versions, Windows 10 has "Open PowerShell window here" by default in the context menu when you Shift+Mouse Right Click on an empty space, and you should be using Windows Terminal by now anyway.
It's even easier in Windows 8.1 and Server 2012 R2. Do this once: Right-click on the task bar, choose Properties. In the Navigation tab, turn on [✓] Replace Command Prompt with Windows PowerShell in the menu when I right-click the lower-left corner or press Windows key+X. Then whenever you want a PowerShell prompt, hit Win+X, I. (Or Win+X, A for an Admin PowerShell prompt)
There's a Windows Explorer extension made by the dude who makes tools for SVN that will at least open a command prompt window. I haven't tried it yet, so I don't know if it'll do PowerShell, but I wanted to share the love with my Stack Overflow brethren: http://tools.tortoisesvn.net/StExBar
Another option are the excellent Elevation PowerToys by Michael Murgolo on TechNet at http://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx. They include PowerShell Prompt Here and PowerShell Prompt Here as Administrator.
By adding the registry keys below, in Windows 10, I managed to get the Open PowerShell Here option in my SHIFT + RClick context menus. Just copy these into a blank notepad file then save as a .reg file and run the file to add the key and it should work from there. Some of these other answers say to add the key into HKCR\Directory\shell but I found that for me it only worked with the keys going into HKLM\SOFTWARE\Classes\Directory\shell Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\powershell] "Extended"="" "NoWorkingDirectory"="" #="Open PowerShell here" "Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\powershell\command] #="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\powershell] #="Open PowerShell here" "Extended"="" "Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" "NoWorkingDirectory"="" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\powershell\command] #="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT if(-not (Test-Path -Path "HKCR:\Directory\shell\$KeyName")) { Try { New-Item -itemType String "HKCR:\Directory\shell\$KeyName" -value "Open PowerShell in this Folder" -ErrorAction Stop New-Item -itemType String "HKCR:\Directory\shell\$KeyName\command" -value "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command Set-Location '%V'" -ErrorAction Stop Write-Host "Successfully!" } Catch { Write-Error $_.Exception.Message } } else { Write-Warning "The specified key name already exists. Type another name and try again." } You can download detail script from how to start PowerShell from Windows Explorer
One fairly simple alternative is to invoke PowerShell via a shortcut. There is a shortcut property labeled "Start in" that says what directory(folder) to use when the shortcut is invoked. If the Start In box is blank, it means use the current directory. When you first create a shortcut to PowerShell in the usual way, the start in box specifies the home directory. If you blank out the start in box, you now have a shortcut to powershell that opens PS in the current directory, whatever that is. If you now copy this shortcut to the target directory, and use explorer to invoke it, you'll start a PS that's pointed at the target directory. There's already an accepted answer to this question, but I offer this as another way.
For autohotkey users, heres a snippet I am using It opens PowerShell window, when pressing Ctrl-Alt-T. (Tested with Win10) If your "active window" is a Windows Explorer -window, then the PowerShell is opened in the current folder. Otherwise, just open PowerShell in some default folder. Usage: 1) Install AutoHotkey, and copy paste this into myscript.ahk 2) Replace <DefaultPath> with path of your choice. 3) Run the script. ; Ctrl-Alt-T opens PowerShell in the current folder, if using Windows Explorer. Otherwise, just open the Powershell. ^!T:: if WinActive("ahk_class CabinetWClass") and WinActive("ahk_exe explorer.exe") { KeyWait Control KeyWait Alt Send {Ctrl down}l{Ctrl up} Send powershell{Enter} } else { psScript = ( cd 'C:\<DefaultPath>' ls ) Run "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" -NoExit -Command &{%psScript%} } return
I created a fully automated solution to add PS and CMD context items. Just run set_registry.cmd and it will update registry to add two buttons when click RMB on folder or inside some opened folder: This will change owner of registry keys to admin and add context menus Change registry to enable PS and CWD context menus
Only this worked for me on Windows 10... Create a file named PowershellHereContextMenu.reg with the contents below, right click on it and "Merge". Windows Registry Editor Version 5.00 ; ; Add context menu entry to Windows Explorer folders ; [HKEY_CLASSES_ROOT\Directory\shell\powershellmenu] #="PowerShell Here" [HKEY_CLASSES_ROOT\Directory\shell\powershellmenu\command] #="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'" ; ; Add context menu entry to Windows Explorer background ; [HKEY_CLASSES_ROOT\Directory\Background\shell\powershellmenu] #="PowerShell Here" "NoWorkingDirectory"="" [HKEY_CLASSES_ROOT\Directory\Background\shell\powershellmenu\command] #="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'" ; ; Add context menu entry to Windows Explorer drive icons ; [HKEY_CLASSES_ROOT\Drive\shell\powershellmenu] #="PowerShell Here" "NoWorkingDirectory"="" [HKEY_CLASSES_ROOT\Drive\shell\powershellmenu\command] #="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
to run PowerShell as an admin in any location of file explorer go to that folder and use the shortcut "alt + f + s + a" to open powershell as an admin in that specific folder location
You can run the below command on the Windows Explorer address bar to open powershell , and it will open the path to this directory. powershell.exe -noexit -command "Write-Host "Hello World""