Jump to content

How to use Get-Credential with Windows containers


Recommended Posts

Guest Vinicius Apolinario
Posted

The idea on this blog post came from an issue opened by an user on the Windows Containers GitHub Repo. I thought the problem faced by the user should be common enough that others might be interested in a solution.

 

 

 

Get-Credential cmdlet pop-up

 

If you use PowerShell, you most likely came across the Get-Credential cmdlet at some point. It’s extremely useful for situations on which you want to set a username and password to be used in a script, variable, etc.. However, the way Get-Credential works is by providing a pop-up window for you to enter the credentials:

 

largevv2px999.png.74b7b223247359709bdd99794b0efa36.png

 

On a traditional Windows environment, this is totally fine as the pop-up window shows up, you enter the username and password, and save the information. However, on a Windows container there’s no place to display the pop-up window:

 

largevv2px999.png.4ad60eceb8c16f8e56be465f2dc0227d.png

 

As you can see on the image above, the command hangs waiting for the confirmation, but nothing happens as the pop-up is not being displayed. Even typing CRTL+C doesn’t work. In my case, I had to close the PowerShell window, which left the container in an exited state.

 

 

 

Changing the Get-Credential behavior

 

To work around this issue, you can change the PowerShell policy to accept credential input from the console session. Here’s the script for that workaround:

 

$key = "HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds"

Set-ItemProperty -Path $key -Name ConsolePrompting -Value $true

 

The next time you use the Get-Credential cmdlet, it will ask for the username and password on the console session:

 

largevv2px999.png.59aa0bdc1f05c2b93f2a4b51c880e5ee.png

 

On the example above, I simply entered the username and password for the Get-Credential cmdlet. You could, obviously, save that on a variable for later use.

 

 

 

While this workaround solves the problem of not being able to use the Get-Credential cmdlet on Windows containers, it’s obviously not ideal. The information from the product team is that they are looking into making this the default option for Windows containers in the future – although, no timelines are available at this moment.

 

 

 

I hope this is useful to you! Let us know in the comments!

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...