davotronic5000 / powershell_credential_manager Goto Github PK
View Code? Open in Web Editor NEWPowerShell Module to Read and Write Credentials from the Windows Credential Manager
License: MIT License
PowerShell Module to Read and Write Credentials from the Windows Credential Manager
License: MIT License
Please remove the Password property from the object returned from New-StoredCredential. This has massive security issues and most Enterprises will not be able to use the module because of it.
Hi,
I'm trying to execute the New-StoredCredential over WinRM session, and I'm getting this error:
ERROR: CredWrite failed with the error code 1312.
windows-2016-x64-virtualbox: ERROR: at , C:\Users\vagrant\set-proxy.ps1: line 22 ERROR: at , : line 1
windows-2016-x64-virtualbox: ERROR EXCEPTION: System.Exception: CredWrite failed with the error code 1312. ERROR EXCEPTION: at PSCredentialManager.Api.CredentialManager.WriteCred(NativeCredential credential) ERROR EXCEPTION: at PSCredentialManager.Cmdlet.NewStoredCredential.ProcessRecord()
This is the snippet I was running:
Write-Host "Setting credential manager"
Import-Module CredentialManager
New-StoredCredential -Target $env:PROXY_HOST -UserName $env:PROXY_USERNAME -Password $env:PROXY_PASSWORD -Type GENERIC -Persist ENTERPRISE
Is there any way I can work around this restriction?
Thank you
Expected behavior:
Get-StoredCredential -Filter myusername | Remove-StoredCredential
Cannot get Remove-StoredCredential to work in any aspect. With or without parameters.
I get the following error with New-StoredCredential
on PowerShell Core 7.
New-StoredCredential : Argument 'New-StoredCredential' is not recognized as a cmdlet: Could not load type 'System.Web.Security.Membership' from assembly 'System
.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The other cmdlets work in Core. All cmdlets work in PowerShell 5.
I would like to use CredentialManager to save PEM-format RSA private key data (typically a few thousand bytes), but there is an explicit 512-char length limit in the module code. Is that from an underlying Window Credential Manager limitation?
When retrieving a stored credential with a blank password Get-StoredCredential displays a warning for the operation and returns nothing.
'Get-StoredCredential -AsCredentialObject' returns the expected PSCredentialManager.Common.Credential object.
somebody know how build it? i cant find reference Microsoft.QualityTools.Testing.Fakes and PSCredentialManager.Api.Fakes
UserName Parameter in New-StoredCredential does not store the username correctly.
To replicate:
New-StoredCredential -Password mypassword -Persist ENTERPRISE -Target TestNewCred -Type GENERIC -UserName TestUser
Get-StoredCredential
and you will see a new credential was created but using the current username ($env:Username)
instead of the credential specified with the UserName paramHi Dave,
First of all, this module looks pretty sweet! I tried it out and it worked like a charm.
In terms of licensing, I wonder why you chose to go with GPL? This has come up as an issue at work in the past. The fear and uncertainty of GPL licensed code is enough to make me think twice about using it at my day job. If nothing else, I'm never going to be knowledgeable enough of the legal implications to feel confident that its worth the risk. Its obviously perfectly fine to install the module on a machine and use it, but what about tools that might take it as a dependency, or bundle it or repackage it in some way?
Anyway, I'm sure I'm not the only person who will ever encounter this question, so I just wanted to make sure you had considered this when choosing the license. Feel free to ignore this or close it as you see fit...
-Bryan
It would be nice if the -Target
property supported autocomplete. Is this something you'd consider accepting a PR for?
(I've previously implemented custom autocompletion for host names in my PsHosts module)
Hi @davotronic5000,
I like the Module and have many uses for it :)
Would be nice if you could add PowerShell help and examples to the commands.
Thanks!
Hello,
When I create a credential using New-Storedcredential, I see it is creating it. I can then fetch it using Get-Storedcredential and it returns to me the credentials.
But when I reboot windows and run Get-Storedcredential, it is gone. What can I do about it? It seems it is not really saving it in the credential manager?
Documentation link showing LOCAL_MACHINE: https://github.com/davotronic5000/PowerShell_Credential_Manager/wiki/New-StoredCredential
Error when using LOCAL_MACHINE:
PS C:\WINDOWS\system32> New-StoredCredential -Target O365 -UserName [email protected] -Persist LOCAL_MACHINE -Password mySuperSecretPassword
New-StoredCredential : Cannot bind parameter 'Persist'. Cannot convert value
"LOCAL_MACHINE" to type "PSCredentialManager.Common.Enum.CredPersist". Error:
"Unable to match the identifier name LOCAL_MACHINE to a valid enumerator name.
Specify one of the following enumerator names and try again:
Session, LocalMachine, Enterprise"
At line:1 char:82
+ ... -UserName [email protected] -Persist LOCAL_MACHINE -Passwo ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-StoredCredential], Par
ameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,PSCredentialManag
er.Cmdlet.NewStoredCredential
Switched to LocalMachine as indicated by error message, working now.
Will this work with Windows 10 and Powershell 5? I get an error when attempting to import. It says it can't load the file or assembly CredentialManager.dll and that the operation isn't supported.
I currently do this boilerplate:
try { $cred = Get-StoredCredential $url } catch {}
if ($cred -eq $null) {
$user = Read-Host -Prompt "Username ($Env:USERDOMAIN\$Env:USERNAME)"
$pass = Read-Host -Prompt "Password" -AsSecureString
$cred = New-Object System.Net.NetworkCredential('', $pass)
New-StoredCredential -Target $url $cred.password
Remove-Variable cred
}
It would also be easier if Get-StoredCredential
would use non terminating error so we could use -ea o
instead of try/catch
block:
$c = Get-StoredCredential $url -ea 0
if (!$c) {...}
Hi ! Thx for that module that helped us a lot !
We have some machines, though, that import the module but have the exportedCommands empty after the import-module.
We used the module on more than 5k computers and only around 10% are failing to get ExportedCommands and thus fail to use the module.
Do you have any idea why only some machines are having this issues ? they all are installed by the same base image and get updated the same way.
Let me know if you need any aditionnal information or if you want me to test something.
Many thanks in advance !
It appears that the last version published to the PSGallery was on 2015-09-07, and that several useful additions have been done since.
Could you push an update 2.0 to the Powershell gallery ?
Publication of the updates to the Gallery would allow me to reference and auto-download your module from scripts I publish there, rather than having to fork and include them in my own modules.
Develop a method to generate passwords in a more customizable way to replace System.Web.Security.Membership.GeneratePassword
When using Get-StoredCredential cmdlet, the target name is not displayed. it would be nice if this command can list target, type, and persistence (similar to cmdkey /list).
Implement XKCD style password in the generator.
http://xkcd.com/936/
Get-StrongPassword -NumberOfSpecialCharacters
Says default value is 3
If i use any value less than 5 (0,1,2,3,4) it seems to return 5 (or more) special characters
0..4 | foreach-object {[pscustomobject]@{'NumSpecial' = $_; 'Password' = Get-StrongPassword -Length 20 -NumberOfSpecialCharacters $_}}
NumSpecial Password
0 JN}ts#!^FycNj[9E]5;&
1 5sIV76]2!oZ>prk9d(P
2 23n8U.}_{kZGzj-ClUbE
3 ]hUPY-QS^Q2cViGk!jf
4 4E>O[FrM]d}@A5qKFv4H
so what is considered a special character
0 has 8, 1 has 5, 2 has 5, 3 has 5, 4 has 5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.