![]() “TwitterSecret” = $(Get-PWfromCredFile “.\TwitterSecret. “GoogClientSecret” = $(Get-PWfromCredFile “.\GoogClientSecret.credential”) $AppSettings = $(Get-PWfromCredFile “.\FB_AppSecret.credential”) De 2022 How to encrypt cifs mount password. # Sample Uses: Read in Cred File to populate app settings array … encrypted password in cifs credentials file Pass2 usernameuser2. Write-host $(Get-PWFromCredFile “.\FB_AppSecret.credential”) $myVar = Get-PWFromCredFile(“.\FB_AppSecret.credential”) # Partner function of Get-PWCreateCredFile.ps1Īuthor: Dan Stolts – dstolts& – Ĭopy portion of script you want to use and paste into PowerShell (or ISE) Purpose: Open and Read XML file with Secure Password stored.Ĭonverts Text Version of Secure String to Plain Text This method has four properties: Domain, Password, SecurePassword, and UserName. "Failed to map $Share to drive $: $($error.= Get-PWFromCredFile.ps1 = # 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). $PlainTextPassword = ConvertFrom-SecureToPlain $Password $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) Fortunately, the problems that we must solve in PowerShell are straightforward, but equally as important: We must store and handle passwords in a way that limits their exposure. In this example, the password is MyPassword. First, convert the plain text password into a SecureString data type. It doesn't do anything useful now if a successful drive mapping is performed it's just an example. This method is not secure because before you create the PSCredential object, you still have to expose the password on the host before encrypting. 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' ![]() '''NB!''' ''Be aware that you should not normally use this one-liner, as it leaves an unfreed pointer instead see the example function above.'' 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. To prompt a user for a password, you can use the cmdlet ''Read-Host'' with the parameter -AsSecureString.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |