Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run dialog execute powershell command

Is there a way to run a powershell command when opening the run box (Windows+R)?

I'd like to just start typing get-process for example and have it execute that command in powershell and display the result (basically opening it and not closing it).

I know you can type "powershell /noexit get-process" to achieve this, but I'd like to know if there's a way the Run box realizes it's a powershell command and all I have to type is the command: get-process.

like image 575
John Smith Avatar asked Feb 10 '23 10:02

John Smith


2 Answers

No, there is no way to make Windows+R understand PowerShell commands directly.

One workaround is to create a batch file with content like this:

@echo off
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -noprofile -noLogo "%1 %2 %3 %4 %5 %6 %7 %8"

name it p.cmd and put it in a location that is in your path.

Now you can do:

Run example

start with p then the PowerShell command you want to execute.

like image 165
Peter Hahndorf Avatar answered Feb 11 '23 23:02

Peter Hahndorf


Might be a bit too late, but you are able to run CMD commands through the run box, and then again PowerShell commands through CMD. By utilizing this you can type:

cmd /k PowerShell.exe "Your PowerShell command"

where the /k can be changed wirh /c if you don't want the CMD-window to stay open. In the end it could look something like this

like image 30
Jagemann Avatar answered Feb 12 '23 00:02

Jagemann