ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Solved [help?] powershell - fixed credential for prompforcredential

    IT Discussion
    3
    7
    1.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      stess
      last edited by

      Hi guys,

      I have a bit of a hiccup with a script I am trying to decode. The code is written by another company to use with their system. I am trying to make an automation where the powershell will read a script from CSV file then execute it on the same PSsession. The challenge I am facing is trying to put a fixed credential when it promp for credential.

      This is the code in question. I am trying to put a fixed credential.

      			$cred = [PsUtils.CredMan]::PromptForCredential("Please enter credentials", "Please enter your credentials.", [Environment]::UserName, $target, "Generic", "None", [ref] $save);
      

      I stumbled across [Creating a PS Credential from a Clear Text Password in Powershell] which seem to be the answer, but somehow it's not.

      Under the same script there is a call function to test the credential. I believed this is what flagging the credential as invalid.

      function Test-Credential([string]$plat, [Management.Automation.PSCredential]$cred)

      NOTE: I tried to reached out to the dev that wrote this code, but the official answer is they will not assist me in modifying the code. The code is "as-is".

      1 Reply Last reply Reply Quote 1
      • DustinB3403D
        DustinB3403
        last edited by

        @stess you can pass credentials as a parameter within powershell.

        S 1 Reply Last reply Reply Quote 0
        • S
          stess @DustinB3403
          last edited by

          @dustinb3403 said in [help?] powershell - fixed credential for prompforcredential:

          @stess you can pass credentials as a parameter within powershell.

          After reading the article, and tinkering with the script, I found that I am passing the credential in the wrong function. I try to pass it in the testing, but I should have pass it in the connection phase.

          Also, I'm surprised this article is so easy to understand.

          DustinB3403D 1 Reply Last reply Reply Quote 1
          • dafyreD
            dafyre
            last edited by

            I can't find any documentation hardly at all about PSUtils.CredMan... If you know of a page, I'd be interested in seeing it.

            What do you get if you do $cred.gettype() ?

            This is how I convert a username / password into a PSCredential object... (My code is tested in WIndows 10 / PowerShell 5.1).

            $username="blahblah"
             $password="youreallydontwantoknow"
              $password=convertto-securestring $password -asplaintext -force
            
              $adCred=New-Object System.Management.Automation.PSCredential -ArgumentList $username,$password
            
            S 1 Reply Last reply Reply Quote 0
            • S
              stess @dafyre
              last edited by

              @dafyre said in [help?] powershell - fixed credential for prompforcredential:

              I can't find any documentation hardly at all about PSUtils.CredMan... If you know of a page, I'd be interested in seeing it.

              What do you get if you do $cred.gettype() ?

              This is how I convert a username / password into a PSCredential object... (My code is tested in WIndows 10 / PowerShell 5.1).

              $username="blahblah"
               $password="youreallydontwantoknow"
                $password=convertto-securestring $password -asplaintext -force
              
                $adCred=New-Object System.Management.Automation.PSCredential -ArgumentList $username,$password
              

              PSUtils is an in-house function written by the dev. It's about 400 lines of code. I'm not even bother to decipher it.

              The problem I has is not the $cred parameters, but where it's being called. In the Test-Credential, it called another function. When I put the $cred = new-object... in that function it just works.

              Basically, It has 5 functions working together: Platform, UserType, Credential, Connection, and Testing. I was trying to pass the $cred in Testing and Credential, but it didn't work. So I pass it in Connection and it works.

              1 Reply Last reply Reply Quote 0
              • DustinB3403D
                DustinB3403 @stess
                last edited by

                @stess said in [help?] powershell - fixed credential for prompforcredential:

                @dustinb3403 said in [help?] powershell - fixed credential for prompforcredential:

                @stess you can pass credentials as a parameter within powershell.

                After reading the article, and tinkering with the script, I found that I am passing the credential in the wrong function. I try to pass it in the testing, but I should have pass it in the connection phase.

                Also, I'm surprised this article is so easy to understand.

                So I guess I get the "Best answer" 😛

                S 1 Reply Last reply Reply Quote 1
                • S
                  stess @DustinB3403
                  last edited by

                  @dustinb3403 said in [help?] powershell - fixed credential for prompforcredential:

                  @stess said in [help?] powershell - fixed credential for prompforcredential:

                  @dustinb3403 said in [help?] powershell - fixed credential for prompforcredential:

                  @stess you can pass credentials as a parameter within powershell.

                  After reading the article, and tinkering with the script, I found that I am passing the credential in the wrong function. I try to pass it in the testing, but I should have pass it in the connection phase.

                  Also, I'm surprised this article is so easy to understand.

                  So I guess I get the "Best answer" 😛

                  Yes you did :winking_face:

                  1 Reply Last reply Reply Quote 1
                  • 1 / 1
                  • First post
                    Last post