Hello,
is there a possible way to crypt the ESX Password in a script with the md5 Hash???
I dont want to save my Scripts unsecured with the Password.
Thanks for your Help.
You could use Hal's Export-PSCredential function.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD.
I have hoped, that this Function can manage with a oneliner in the script.
This Script make me confused ?:|
When you store both functions in the profile it becomes a one-liner in your script.
You would just have to do, for example
Import-PSCredential -Path "C:\Credentials\MyCred.xml"
The file has to be created beforehand with
Export-PSCredential -Path "C:\Credentials\MyCred.xml"
The function will prompt you to enter an account and password.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
I think you can provide password at run time only, no need to store password
Connect-VIServer -Server <> -User <> -Password (read-host -prompt "Enter password")
So, you don’t have to save password.
Or else you still want to encrypt password just try this couple of lines ,
$pas = read-host -prompt "Enter password" -assecurestring
$ptr = http://System.Runtime.InteropServices.Marshal::SecureStringToBSTR($pas)
Connect-VIServer -Server <> -User <> -Password (http://System.Runtime.InteropServices.Marshal::PtrToStringAuto($ptr))
Hope this helps.
http link is automatically attached by forum thread, pls remove http and use as "[System.."
$pas = read-host -prompt "Enter password" -assecurestring
$ptr = http://System.Runtime.InteropServices.Marshal::SecureStringToBSTR($pas)
Connect-VIServer -Server <> -User <> -Password (http://System.Runtime.InteropServices.Marshal::PtrToStringAuto($ptr))
That is a good solution, provided you run your scripts interactively.
When you schedule scripts, or when you execute scripts as an alarm action this won't work I'm afraid.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Untill recently i used a encrypted password file, which was created with the service account. But now i use a database with encrypted passwords.
Thanks for your helps.
I will need this for the command Add-VMHost -user root -Password CRYPT and not for the "Connect-VIServer". For this i have the command
I will test this when i have time.
Use the attached powershell script to create and encrypted password file. I have been using this for quit some time now.
Use the following snippet to read the file and convert the password:
#READ ENCRYPTED PASSWORD
$READFILE = Get-Content $PASSFILE | ConvertTo-SecureString
$CONVERT_PASSWORD = http://System.Runtime.InteropServices.Marshal::SecureStringToBSTR($READFILE)
$passwd = http://System.Runtime.InteropServices.Marshal::PtrToStringAuto($CONVERT_PASSWORD)