Powershell get-credentials fails

懵懂的女人 提交于 2019-12-24 00:45:17

问题


PS C:\Windows\system32> $creds = Get-Credential

cmdlet Get-Credential at command pipeline position 1 Supply values for the following parameters: Credential

PS C:\Windows\system32> $ses = New-PSSession -ComputerName WIN-O4VC136J0E2 -Credential $creds

New-PSSession : [WIN-O4VC136J0E2] Connecting to remote server WIN-O4VC136J0E2 failed with the following error message : The user name or password is incorrect. For more information, see the about_Remote_Troubleshooting Help topic. At line:1 char:8 + $ses = New-PSSession -ComputerName WIN-O4VC136J0E2 -Credential $creds + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin gTransportException + FullyQualifiedErrorId : LogonFailure,PSSessionOpenFailed

The credentials I used are the same ones I used to login manually. Is there something else I am doing wrong? I've tried several different ways and never can seem to login.


回答1:


Try the following, works very nicely with either a domain account or local account:

# Enter your pass and stores it securely:
$SecureString = Read-Host -AsSecureString 'Enter your password ' | ConvertFrom-SecureString | ConvertTo-SecureString
# Users you password securly
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "MyLoCalMachine\MyUserID",$SecureString
# Sets yous credentials to be used
$RemoteConn = New-PSSession -ComputerName $ts -Credential $MySecureCreds -Authentication default


来源:https://stackoverflow.com/questions/27736735/powershell-get-credentials-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!