2 Replies Latest reply on Aug 13, 2019 5:59 AM by jvm2016

    password _powershell

    jvm2016 Hot Shot

      Hi Luc ,


      can you please suggest what needs to be modified in below code to make it functioning.


      read-host -assecurestring | convertfrom-securestring | out-file D:\jai\ps_script\passnew.txt

      $password = get-content D:\jai\ps_script\passnew.txt | convertto-securestring

      $credentials = new-object -typename System.Management.Automation.PSCredential("administrator@vsphere-tch.local ",$password)

      Connect-VIServer -server vcenter1 -Credential $credentials



      for some reasons iam getting invalid credential .i am trying to run Health check script automatically with any user intervention .

        • 1. Re: password _powershell
          LucD Guru
          Community WarriorsvExpertUser Moderators

          That code is correct.
          But you have a blank at the end of the username that might be causing a problem.


          Read-Host -assecurestring | ConvertFrom-SecureString | Out-File D:\jai\ps_script\passnew.txt

          $password = Get-Content -path C:\Temp\passnew.txt | ConvertTo-SecureString

          $credentials = new-object -typename System.Management.Automation.PSCredential("administrator@vsphere-tch.local",$password)

          Connect-VIServer -server vcenter1 -Credential $credentials

          • 2. Re: password _powershell
            jvm2016 Hot Shot

            Thanks it worked .