Code Monkey home page Code Monkey logo

powershell_credential_manager's Introduction

PowerShell Credential Manager

PowerShell Module to Read and Write Credentials from the Windows Credential Manager

Ongoing Development and Support

I am no longer working on this project or PowerShell much at all. If anyone else wants to take a fork and continue supporting this project. I would be happy to link to that project from here to guide people in the right direction.

Installation

###PowerShell Gallery Installation The module is available on the PowerShell Gallery: https://www.powershellgallery.com/packages/CredentialManager/1.0.0.

  1. PS> Save-Module -Name CredentialManager -Path
  2. PS> Install-Module -Name CredentialManager

###Manual Installation

  1. Dowload the latest verion of the module code from https://github.com/davotronic5000/PowerShell_Credential_Manager/releases
  2. Unzip CredentialManager.zip and copy the contents to you preferred module path. Usually C:\Users$UserName\Documents\WindowsPowerShell\Modules.
  3. In your PowerShell session run the command Import-Module CredentialManager

Usage

Import the module in to your PowerShell session and full help is available in the module with Get-Help

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

History

v2.0

  • Implemented pipeline support for Get-StoredCredential.
  • Implemented pipeline support for New-StoredCredential.
  • Implemented pipeline support for Remove-StoredCredential.
  • Improved error handling to respect the Error Action Preference in PowerShell.
  • Changed AsPSCredential to a Switch parameter and renamed to AsCredentialObject on Get-StoredCredential to make it easier to use.
  • Added Credentials parameter to New-StoredCredential which accepts a PSCredential object instead of User name and Password.
  • Added SecuserPassword parameter to New-StoredCredential which accepts a SecureString as the password.
  • Credential object now returns LastWritten as a DateTime instead of a ComType.FILETIME
  • Changing license to MIT from GPL
  • General refactoring and bug fixes.

v1.1 Bug Fix

Fixed a bug where the username specified in the -UserName parameter was not being used to create the credential in the store. The username for the logged on user was being used instead. Issue logged #8

v1.0 Initial Release

Implementing basic functionality

  • Get-StoredCredential - Gets one or more credentials from the Windows Credential Manager.
  • New-Stored Credential - Adds a new credential to the Windows Credential Manager.
  • Remove-StoredCredential - Deletes a credential from the Windows Credential Manager.
  • Get-StrongPassword - Randomly generates a new password.

Credits

Written by Dave Garnar (@davotronic5000) http://blog.davotronic5000.co.uk

License

This software is licensed under the The MIT License (MIT).

Copyright (C) 2016 Dave Garnar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

powershell_credential_manager's People

Contributors

techgerm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

powershell_credential_manager's Issues

Not compatible with PowerShell Core

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.

Import error

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.

how build it?

somebody know how build it? i cant find reference Microsoft.QualityTools.Testing.Fakes and PSCredentialManager.Api.Fakes

Documentation Specifies LOCAL_MACHINE, looks like Enumerator name is actually LocalMachine

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.

ExportedCommands empty on some machines

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 !

Improve Password Generation

Develop a method to generate passwords in a more customizable way to replace System.Web.Security.Membership.GeneratePassword

Credentials not stored after reboot

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?

Add autocomplete support for -Target

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)

Why the 512-byte length limit on passwords?

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?

Licensing question

Hi 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

New-StoredCredential should also accept securestring as password

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) {...}

UserName Parameter in New-StoredCredential does not store the username correctly.

UserName Parameter in New-StoredCredential does not store the username correctly.

To replicate:

  1. Run the following New-StoredCredential -Password mypassword -Persist ENTERPRISE -Target TestNewCred -Type GENERIC -UserName TestUser
  2. Run 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 param

PowerShell gallery appears outdated

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.

Get-StrongPassword -NumberOfSpecialCharacters

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^Q2cVi
Gk!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

Remove-StoredCredential non-functional

Expected behavior:

Get-StoredCredential -Filter myusername | Remove-StoredCredential

Cannot get Remove-StoredCredential to work in any aspect. With or without parameters.

Running New-StoredCredential over WinRM produce error

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.