

- #GET PLAIN TEXT PASSWORD FORM PSCREDENTIAL HOW TO#
- #GET PLAIN TEXT PASSWORD FORM PSCREDENTIAL WINDOWS#
# Check if it failed, exit if it did, and print the error. $Drive.MapNetworkDrive($DriveLetter, $Share, 'false', $Username, $PlainTextPassword) | Out-Null $ErrorActionPreference = 'Silentl圜ontinue' $Drive = New-Object -ComObject WScript.Network # Try to map the drive and hide errors (will be displayed later). Although this may be a temporary fix, it will get you through the errors created by. $PlainTextPassword = ConvertFrom-SecureToPlain $Password Enable secret password is stored in encrypted form in the routers. $Password = Read-Host -AsSecureString 'Please enter your password (it will not be displayed)' $Username = Read-Host 'Please enter a username and domain in the form DOMAIN\USERNAME' $PlainTextPassword = ::PtrToStringAuto($PasswordPointer) # Get the plain text version of the password. $PasswordPointer = ::SecureStringToBSTR($SecurePassword) It doesn't do anything useful now if a successful drive mapping is performed it's just an example. The script will exit if a connection can not be made. PS C:\> ::PtrToStringAuto(::SecureStringToBSTR($SecureString))Įxample Script for Mapping a Network Drive With Alternate CredentialsThis demonstrates how you could check if a server is available for mapping network drives against. PS C:\> $SecureString = Read-Host -AsSecureString 'Enter password' User: username1 Password for user username1: > creds.GetNetworkCredential (). > creds Get-Credential Enter your credentials. '''NB!''' ''Be aware that you should not normally use this one-liner, as it leaves an unfreed pointer instead see the example function above.'' The GetNetworkCredential () method returns a password property in a clear string format. This guy uses some methods that seem to be Unicode-specific from the same class in a related article. Another helpful person later made me aware that this left an unfreed pointer, so make sure you check out the example function for properly handling the pointer.ĭemonstration of Converting SecureString to Plain TextĪs you can see below, the class is where the most relevant stuff seems to be.

He said he thought he found it buried deep in an Exchange cmdlet somewhere. A helpful person I came across had done it and had the magic incantation required, which I am now making easily available for others who might not run into this same helpful person. I searched the web for a while, but didn't find a way to convert the secure string back into plain text. The cmdlet ''New-PSDrive'' doesn't accept the -Credential parameter in PowerShell v2. Specifically, I wanted to specify alternate credentials for mapping a network drive. The problem I ran into was when I wanted to use it in conjunction with a COM method call that needed the password in plain text. Sounds easy enough We’ll tackle each of these points in turn. mof file, we tell it to use the certificate file to encrypt the PSCredential s with, and Powershell won’t complain anymore about storing passwords in plain text. To prompt a user for a password, you can use the cmdlet ''Read-Host'' with the parameter -AsSecureString. On the sending side, whenever we run our Configuration to generate the.
#GET PLAIN TEXT PASSWORD FORM PSCREDENTIAL WINDOWS#
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft.
#GET PLAIN TEXT PASSWORD FORM PSCREDENTIAL HOW TO#
Submission Guidelines | Link Flair - How To The returned password should be the same password you provided to the PSCredential constructor.xample Code: credential.GetNetworkCredential().Password To see.
