Scripts

Welcome to the Nutanix NEXT community. To get started please read our short welcome post. Thanks!

cancel
Showing results for 
Search instead for 
Did you mean: 

Automate Powershell script authentication

SOLVED Go to solution
Highlighted
Pathfinder

Automate Powershell script authentication

Hello.  I'm currently running a few Powershell scripts interactively in order to gather cluster and VM information from our AHV cluster.  I'd like to automate the execution of this from Task Scheduler, but I've been unable to find any way to automate the authentication to the cluster.  In other platforms, you can do this by creating a secured credential and then accessing it and passing it to the authentication cmdlet.

 

Is this currently possible?  If not, I'd like to submit a feature request as we are automating a number of our capacity planning via powershell.  Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Nutanix Employee

Re: Automate Powershell script authentication

@gmatt2017

 

Add "ForcedConnection"  to skip version check.

 

$pwd = ConvertTo-SecureString $password -AsPlainText -Force

$username = "user_name"
Connect-NTNXCluster -Server $server -UserName $UserName -Password $pwd -AcceptInvalidSSLCerts -ForcedConnection

7 REPLIES
Nutanix Employee

Re: Automate Powershell script authentication

@gmatt2017

 

Are you looking for the CMDlet to connect to cluster via Powershell? If so , then you can use 

Connect-NTNXcluster

Pathfinder

Re: Automate Powershell script authentication

I'm already using that cmdlet.  What I need is to be able to authenticate to the AHV cluster without it requiring interactive username/password as this means we can't automate the entire process.  Is there a way to do this?

Nutanix Employee

Re: Automate Powershell script authentication

@gmatt2017 You can use the following command to do the auth

 

$pass=ConvertTo-SecureString "Password1"  -AsPlainText -force
Connect-NTNXCluster -UserName admin -Password $pass -AcceptInvalidSSLCerts -Server <ipaddress>

Is this you are looking for? 

Nutanix Employee

Re: Automate Powershell script authentication

@gmatt2017

 

Add "ForcedConnection"  to skip version check.

 

$pwd = ConvertTo-SecureString $password -AsPlainText -Force

$username = "user_name"
Connect-NTNXCluster -Server $server -UserName $UserName -Password $pwd -AcceptInvalidSSLCerts -ForcedConnection

Pathfinder

Re: Automate Powershell script authentication

Yes, that is basically what I was looking for.  I'm writing a script that will be executed automatically on a schedule so I need to be able to authenticate non-interactively.  I was struggling with doing this while avoiding putting the plain text password in the script itself.  I found a way to do it by converting to securestring and writing that value to a file, which I can than read in and convert before passing back into the script for authentication.

 

Example - 

$SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString
(enter the password for the user account here and press Enter)
$SecureStringAsPlainText = $securepassword | ConvertFrom-SecureString
$SecureStringAsPlainText | set-content C:\password.txt

 

Then read that into the script when it executes as follows:

$user = "username@domain.com"
$SecureString = (get-content C:\password.txt | ConvertTo-SecureString)
Connect-NTNXCluster <clustername> -UserName $user -Password $SecureString -AcceptInvalidSSLCerts

 

Maybe this will help someone else.  Thanks!

Nutanix Employee

Re: Automate Powershell script authentication

Nutanix Employee

Re: Automate Powershell script authentication

@gmatt2017

How are you?

Hope we were able to answer your queries.

If so, please mark the post as resolved