[help?] powershell - fixed credential for prompforcredential
- 
 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". 
- 
 @stess you can pass credentials as a parameter within powershell. 
- 
 @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. 
- 
 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
- 
 @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,$passwordPSUtils 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. 
- 
 @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"  
- 
 @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: 

