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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With