New-Object : Cannot find an overload for “PSCredential” and the argument count: “2”

前端 未结 2 659
清歌不尽
清歌不尽 2020-12-30 19:16

I am writing a PowerShell script on a Windows 8.1 machine. When trying to create a PSCredential object using New-Object cmdlet, I was presented with this error:

New-

2条回答
  •  囚心锁ツ
    2020-12-30 19:56

    Also remember that if you don't need a specific credential other than the current credential of the person running the command (or script), you can skip all this with a one-liner:

    $Cred = Get-Credential
    

    A popup will then prompt you to enter your username and password. Just like that, you've captured your credentials in a variable that you can use at the command line or you can use this in a script to prompt the user for their credentials.

提交回复
热议问题