0

Whenever I login to my servercore server, the first thing i usually do is this:

powershell start-process powershell -verb runas

It's a little annoying to always write this whole sentence. can I somehow shorten this?

powershell start powershell -v runas

is the shortest version I can come up with. Is there a way to alias powershell to ps or posh or something in cmd? Or any other command that does this and doesn't take such a long time to write?

Thanks!

  • one idea that just came to my mind is function posh { start powershell -v runas } in my powershell profile so I can do powershell posh in cmd, but sometimes I don't want a PS Profile on my server, so any other ideas are more than welcome – SimonS Feb 17 '17 at 13:11
  • If you start in cmd.exe and you always want to start an elevated PowerShell prompt, you could create a .cmd batch file that contains the line and distribute it via Group Policy. – Bill_Stewart Feb 17 '17 at 14:51
1

You could autostart a batch with the command

@powershell start-process powershell -verb runas

There is no need for 3rd party tools - use doskey.exe.

doskey PS=powershell start-process powershell -verb runas 

And only enter PS in future. To have doskey available in every cmd instance insert an autorun in registry (and store your preferred macros in a file to preload)

I use this batch to automate this. If not present it creates a file aliases.txt in the userprofile folder, runs doskey with this file and generates a registry autorun entry to do this when cmd.exe runs.

@Echo off
Set "Aliases=%UserProfile%\Aliases.txt"
If Not Exist "%Aliases%" (
  Echo CDD=CD /D $*
  Echo X=Exit /b 0
  Echo clear=cls
  Echo Alias=Doskey $*
  Echo Aliases=Doskey /MACROS:ALL
  Echo mc=far
  Echo PS=powershell start-process powershell -verb runas
)>"%Aliases%"
Doskey /Macrofile="%Aliases%"

Set "Key=HKCU\Software\Microsoft\Command Processor"
Reg ADD "%Key%" /f /v AutoRun /t REG_SZ /d "Doskey /MacroFile=\"%Aliases%\""
1

There are keyboard macro tools you can run on your workstation. A hotkey can be programmed to send any key sequence you like, even if the active window is a RDP, SSH, whatever to a remote system. Specific product recommendations are prohibited on the site, unsure if this next sentence will be flagged/removed. If you look around, you may find one that can be abbreviated AHK.

  • I don't think production recommendations, AutoHotkey in this case, are prohibited.... It's that questions which are merely production recommendation requests are off-topic. Please do recommend a product if you feel it would benefit or suppliment your answer. – jscott Feb 17 '17 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.