8 Replies Latest reply on Jul 16, 2020 10:56 AM by ganapa2000

    Need help in validating Passwords

    ganapa2000 Hot Shot

      Hi,

       

      I am unable to validate and execute the below scripts, When I have multiple passwords

       

      Please help

       

      $reportlocation1 = ".\Clients_Mgmt.csv"

       

      $WPassword = "Password1", "Password2", "Password3"

      $pass = ConvertTo-SecureString -AsPlainText $WPassword -Force

      $Creds = New-Object System.Management.Automation.PSCredential ("admin", $pass)

       

      $code = @'

      "### Output ###"

      (Get-Date)

      '@

       

      $report = @()

      Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |

      ForEach-Object -Process {

         foreach ($pswd in $pass)

         {

          $sInvoke = @{

              VM              = $_.Name

              GuestCredential = $Creds

              ScriptTYpe      = 'powershell'

              ScriptText      = $code

          }

          $result = Invoke-VMScript @sInvoke

          $dummy, $out1 = $result.ScriptOutput -split '### Output ###'

          $out1 = $out1.TrimStart("`n`r")

          $report += $row | Add-Member -MemberType NoteProperty -Name 'DateTime' -Value ([DateTime]::Parse($out1)) -PassThru

          }

          }

       

      $report | ft -auto

        • 1. Re: Need help in validating Passwords
          LucD Guru
          Community WarriorsvExpertUser Moderators

          I'm not sure what you are trying to do.
          Finding a working password?

          Or getting that DateTime property, independent which password was used?

          And what when none of the passwords work?

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Need help in validating Passwords
            ganapa2000 Hot Shot

            LucD,

             

            I want to get the time from the Guest VM using the working Password.

             

            If non of the passwords work, I want to capture the VM Name in the different file.

            • 3. Re: Need help in validating Passwords
              LucD Guru
              User ModeratorsCommunity WarriorsvExpert

              Try like this

               

              $reportlocation1 = ".\Clients_Mgmt.csv"

              $WPassword = "Password1", "Password2", "Password3"

              $user = 'admin'


              $code = @'

              "### Output ###"

              (Get-Date)

              '@


              $report = @()

              $notFound = @()


              Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |

              ForEach-Object -Process {

                  $found = $false

                  foreach ($pswd in $WPassword) {

                      $pass = ConvertTo-SecureString -AsPlainText $pswd -Force

                      $Creds = New-Object System.Management.Automation.PSCredential ($user, $pass)


                      $sInvoke = @{

                          VM              = $row.Name

                          GuestCredential = $Creds

                          ScriptTYpe      = 'powershell'

                          ScriptText      = $code

                          ErrorAction = 'Stop'

                      }

                      try {

                          $result = Invoke-VMScript @sInvoke

                          $dummy, $out1 = $result.ScriptOutput -split '### Output ###'

                          $out1 = $out1.TrimStart("`n`r")

                          $report += $row | Add-Member -MemberType NoteProperty -Name 'DateTime' -Value [DateTime]::Parse($out1) -PassThru

                          $found = $true

                          break

                      }

                      catch {

                      }

                  }

                  if(-not $found){

                      $notFound += $row

                  }

              }


              $report | Format-Table -AutoSize


              $notFound | Format-Table -AutoSize

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Need help in validating Passwords
                ganapa2000 Hot Shot

                LucD,

                 

                That worked. But I one last thing, How can I add Password Column added to the output to get which Password Worked ?

                 

                Like Password1 or Password2

                • 5. Re: Need help in validating Passwords
                  LucD Guru
                  Community WarriorsUser ModeratorsvExpert

                  Something like this?

                   

                  $reportlocation1 = ".\Clients_Mgmt.csv"

                  $WPassword = "Password1", "Password2", "Password3"

                  $user = 'admin'


                  $code = @'

                  "### Output ###"

                  (Get-Date)

                  '@


                  $report = @()

                  $notFound = @()


                  Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |

                  ForEach-Object -Process {

                      $found = $false

                      $pswdNr = 1

                      foreach ($pswd in $WPassword) {

                          $pass = ConvertTo-SecureString -AsPlainText $pswd -Force

                          $Creds = New-Object System.Management.Automation.PSCredential ($user, $pass)


                          $sInvoke = @{

                              VM              = $row.Name

                              GuestCredential = $Creds

                              ScriptTYpe      = 'powershell'

                              ScriptText      = $code

                              ErrorAction = 'Stop'

                          }

                          try {

                              $result = Invoke-VMScript @sInvoke

                              $dummy, $out1 = $result.ScriptOutput -split '### Output ###'

                              $out1 = $out1.TrimStart("`n`r")

                              $report += $row | Add-Member -MemberType NoteProperty -Name 'DateTime' -Value ([DateTime]::Parse($out1)) -PassThru |

                                  Add-Member -MemberType NoteProperty -Name 'Password' -Value $pswdNr -PassThru

                              $found = $true

                              break

                          }

                          catch {

                          }

                          $pswdNr++

                      }

                      if(-not $found){

                          $notFound += $row

                      }

                  }


                  $report | Format-Table -AutoSize


                  $notFound | Format-Table -AutoSize

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: Need help in validating Passwords
                    ganapa2000 Hot Shot

                    LucD,

                     

                    I am unable to get the Time output and Password details in the output.

                     

                    I just see, what ever I have in the input file as output.

                    • 7. Re: Need help in validating Passwords
                      LucD Guru
                      User ModeratorsvExpertCommunity Warriors

                      I placed parenthesis around the Value of the 1st Add-Member.

                      That should work now

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: Need help in validating Passwords
                        ganapa2000 Hot Shot

                        Thank you very much. That worked perfectly

                         

                        You are simply superb as always.