VMware Cloud Community
wolficool
Contributor
Contributor

Add-VMHost Password md5

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.

0 Kudos
9 Replies
LucD
Leadership
Leadership

You could use Hal's Export-PSCredential function.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
wolficool
Contributor
Contributor

Thanks LucD.

I have hoped, that this Function can manage with a oneliner in the script.

This Script make me confused ?:|

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
jeveenj
Enthusiast
Enthusiast

Hi,

I think you can provide password at run time only, no need to store password Smiley Happy

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 Smiley Happy,

$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.

-If you found this information useful, please consider awarding points for Correct or Helpful.
0 Kudos
jeveenj
Enthusiast
Enthusiast

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))

-If you found this information useful, please consider awarding points for Correct or Helpful.
0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
RobMokkink
Expert
Expert

Untill recently i used a encrypted password file, which was created with the service account. But now i use a database with encrypted passwords.

0 Kudos
wolficool
Contributor
Contributor

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.

0 Kudos
RobMokkink
Expert
Expert

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:

#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)

0 Kudos