Last active
April 27, 2020 16:04
-
-
Save shuguet/6cb4577414357c25dbeb3d018a4b7373 to your computer and use it in GitHub Desktop.
How to use encrypted password in NTNX PowerShell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Creating AES key with random data and export to file: | |
$KeyFile = "c:\AES.key" | |
$Key = New-Object Byte[] 16 # You can use 16, 24, or 32 for AES | |
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key) | |
$Key | out-file $KeyFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Creating SecureString object: | |
$PasswordFile = "c:\Password.txt" | |
$KeyFile = "c:\AES.key" | |
$Key = Get-Content $KeyFile | |
$Password = "nutanix/4u" | ConvertTo-SecureString -AsPlainText -Force | |
$Password | ConvertFrom-SecureString -key $Key | Out-File $PasswordFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define a few variables | |
$User = "admin" | |
$NTNXCluster = "my.nutanix.cluster.local.ip" | |
$PasswordFile = "c:\Password.txt" | |
$KeyFile = "c:\AES.key" | |
#Creating PSCredential object | |
$key = Get-Content $KeyFile | |
$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential ` | |
-ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key) | |
Connect-NTNXCluster -Server $NTNXCluster -UserName $MyCredential.UserName -Password $MyCredential.Password -AcceptInvalidSSLCerts -ForcedConnection | |
Get-NTNXVM | select VMName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment