Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PSCredential Overload Error

In powershell I want to use the username and password which are stored in $uname, $pass. These are actually read from a file and is stored in $uname and $pass, each time the script executes. I have tried like

$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $uname,$pass

But the error is

new-object : Cannot find an overload for "PSCredential" and the argument count: "2".

I need to use these credentials for a New-PsSession later on in the script. Can someone please help at the earliest?

like image 924
serverstackqns Avatar asked Apr 12 '15 07:04

serverstackqns


People also ask

What is PSCredential?

The PSCredential object represents a set of security credentials such as a user name and password. The object can be passed as a parameter to a function that runs as the user account in that credential object. There are a few ways that you can create a credential object.

How do you create a PSCredential object?

Typically, to create a PSCredential object, you'd use the Get-Credential cmdlet. The Get-Credential cmdlet is the most common way that PowerShell receives input to create the PSCredential object like the username and password. The Get-Credential cmdlet works fine and all but it's interactive.


1 Answers

You will have to convert your plaintext password to a secure string first:

$password=$pass|ConvertTo-SecureString -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PsCredential("[email protected]",$password)
like image 93
Loïc MICHEL Avatar answered Nov 15 '22 09:11

Loïc MICHEL