windows - Powershell 获取凭据失败

标签 windows powershell credentials

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

我使用的凭据与我手动登录时使用的凭据相同。还有什么我做错了吗?我尝试了几种不同的方式,但似乎永远无法登录。

最佳答案

尝试以下方法,无论是域帐户还是本地帐户都能很好地工作:

# 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

关于windows - Powershell 获取凭据失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27736735/

相关文章:

PHP Rename() 删除 Windows 中的所有者属性?

windows - 如何从 Windows 命令行运行 Maxima

python - Python 中 API 的 OAuth2 授权

azure - 如何使用 Get-AzWebApp 命令列出所有自定义域和订阅名称

json - 仅当保存到变量时,powershell json转换问题才能纠正结果

java - 以原子方式更改 c3p0 ComboPooledDataSource 中的凭据

git - 无法连接到centos中的azure git

mysql - 无法更改Mysql服务器的时区

java - 使用 Inno setup 在启动文件夹中创建快捷方式

powershell - 添加自定义属性或替换只读属性