Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Elevate PowerShell 6.0 to RunAs Admin

Prior to PowerShell 6.0 to elevate your session you ran the command

Start-Process powershell -Verb runAs

When trying to run the similar command in PowerShell 6.0

Start-Process pwsh -Verb runAs

You get this output:

Start-Process : The parameter '-Verb' is not supported for the cmdlet 'Start-Process' on this edition of PowerShell.
At line:1 char:1
+ Start-Process pwsh -Verb runAs
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) [Start-Process], NotSupportedException
+ FullyQualifiedErrorId : NotSupportedException,Microsoft.PowerShell.Commands.StartProcessCommand

So how do I elevate to run as administrator in PowerShell 6.0?

I am running the PowerShell Windows Nano Server docker image (microsoft/powershell:nanoserver)

like image 627
Joshua Avatar asked Feb 02 '18 21:02

Joshua


1 Answers

What I was wanting to accomplish when I posted my question was to add certificates to the Windows certificate store using the following command:

certoc.exe -addstore root corporaterootssl.cer

The message I was receiving when executing this command in the Windows Nano Server container was access denied. This was because I was running the container with the standard user ContainerUser using the command:

docker run -d  microsoft/powershell:nanoserver

I would connect to the container with the command:

docker exec -it  gracious_ramanujan pwsh

This would put me in the container running as ContainerUser. To enter the container as ContainerAdministrator I needed to run the command:

docker exec -it --user ContainerAdministrator  gracious_ramanujan pwsh

Then I was able to successfully run any administrative commands.

My ultimate goal was to build a container image during which I needed to run one or more commands as an administrator. To switch users in your Dockerfile you use the command USER ContainerAdministrator. I wrote a blog post detailing how to add SSL certificates to your image during your Docker build process.

like image 161
Joshua Avatar answered Oct 07 '22 05:10

Joshua