Sooner or later, every administrator comes to the fact that he needs some way to save and retrieve credentials. And it should be fast, efficient, convenient and most importantly securely.
None of the methods known to me did not meet all these requirements at once. I began to search and found my way, which I want to share with you. This is PowerCLi! Are you surprised? Sometimes the simplest solution is on the surface.
- The PowerCLi contains three
gcm -Noun vicred*
- These cmdlets very simple to use. The
New-VICredentialStoreItemcreates a new or updates existing credential store item.
New-VICredentialStoreItem -Host ps1code -User Administrator -Password P@ssw0rd
Get-VICredentialStoreItemcan retrieve the items and even show the items’ passwords as clear text!
Get-VICredentialStoreItem –Host ps1code | select Host, User, Password Get-VICredentialStoreItem | select Host, User, Password
- You more no need the item(s)? Do remove it/them by
Get-VICredentialStoreItem –Host ps1code | Remove-VICredentialStoreItem Get-VICredentialStoreItem | Remove-VICredentialStoreItem -Confirm:$false
- It would seem that everything is fine, but there is one problem. We cannot directly use object, returned by
Get-VICredentialStoreItemas value for
Get-VICredentialStoreItem | Get-Member Add-VMHost -Credential (Get-VICredentialStoreItem -Host ps1code) Get-Help Add-VMHost -Parameter Credential
- Here the
Convert-VI2PSCredentialfunction from my PowerCLi Vi-Module module will help us.
Convert-VI2PSCredentialconverts credentials, returned by
Get-VICredentialStoreItemto the well-known
Get-VICredentialStoreItem -Host ps1code | Convert-VI2PSCredential
- This will allow us to use PowerCLi credentials with any cmdlet (not only PowerCLi) that supports
-Credentialparameter!!! There are many such …
Get-Command -ParameterName credential Get-Command -ParameterName credential -Module azure*
- Now you can safely save your credentials by
New-VICredentialStoreItem, then retrieve them by
Get-VICredentialStoreItem, convert it by
Convert-VI2PSCredentialand pass it to the
- Let’s for example login to the Azure with saved PowerCLi credentials. The
-Hostvalue is only pointer for selecting item by
Get-VICredentialStoreItem -Host, it will not be part of the credentials!
New-VICredentialStoreItem -Host Azure -User email@example.com -Password $Password Import-Module AzureRM Login-AzureRmAccount -Credential (Get-VICredentialStoreItem -Host azure | vi2ps)
vi2psis the alias for the
Get-Alias -Definition Convert-VI2PSCredential
- For more details about the function, please take a look at the content based help and examples.
Get-Help Convert-VI2PSCredential -Full Get-Help Convert-VI2PSCredential -Examples