VMware Cloud Community
fredlock
Contributor
Contributor
Jump to solution

How to use password -AsSecureString in the script

I like to prompt my script for the Active Directory User ID and password, and use it further on in the script to connect-VIServers

something like...

$MyAdUserID = Read-Host "Enter Active Directory UserID"

$MyAdPassword = Read-Host "Enter Password" -AsSecureString

# now i want to connect to a sequence of vSphere5 hosts

connect-viserver <hostname> -user $MyAdUserID -password $MyAdPassword

It cannot authenticate with the SecureString password

How to make it work?

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There is some conversion required to use the password.

The easiest way is to use the Credential parameter.

$MyAdUserID = Read-Host "Enter Active Directory UserID" 
$MyAdPassword = Read-Host "Enter Password" -AsSecureString
$cred
= New-Object System.Management.Automation.PSCredential -ArgumentList $MyAdUserID,$MyAdPassword
Connect-VIServer
<hostname> -Credential $cred

And have a look at Arnim's post Bulk change your ESX root password, I think it does what you are looking for.


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

There is some conversion required to use the password.

The easiest way is to use the Credential parameter.

$MyAdUserID = Read-Host "Enter Active Directory UserID" 
$MyAdPassword = Read-Host "Enter Password" -AsSecureString
$cred
= New-Object System.Management.Automation.PSCredential -ArgumentList $MyAdUserID,$MyAdPassword
Connect-VIServer
<hostname> -Credential $cred

And have a look at Arnim's post Bulk change your ESX root password, I think it does what you are looking for.


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

Reply
0 Kudos
fredlock
Contributor
Contributor
Jump to solution

What a cool and simple solution!

Thanks again LucD!

No it is for audit things like reporting local users etc.

Thanks

Reply
0 Kudos