您好我想使用power shell登录我的远程服务器。我为此编写了代码,但是我收到了错误。
CODE
$cred = get-credential - Prompts for username and password
Enter-PSSession -ComputerName servername -Credential $cred
错误
Get-Credential:找不到接受的位置参数 论证'提示'。在C:\ documents \ Untitled8.ps1:1 char:9 + $ cred = get-credential - 提示输入用户名和密码 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 〜 + CategoryInfo:InvalidArgument:(:) [Get-Credential],ParameterBindingException + FullyQualifiedErrorId:PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetCredentialCommand
Enter-PSSession:连接到远程服务器XXXXX失败了 以下错误消息:访问被拒绝。有关更多信息,请参阅 about_Remote_Troubleshooting帮助主题 C:\ documents \ Untitled8.ps1:5 char:1 + Enter-PSSession -ComputerName servername -Credential $ cred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ + CategoryInfo:InvalidArgument:(servername:String)[Enter-PSSession],PSRemotingTransportException + FullyQualifiedErrorId:CreateRemoteRunspaceFailed
任何关于此的线索都会有所帮助....
的 Get-Credential : A positional parameter cannot be found that accepts argument 'Prompts'
任何人都知道如何使用servername登录电源shell中的远程服务器..任何关于此的链接都会有帮助
答案 0 :(得分:1)
问题在于它找不到位置参数,其中“提示”被接受。如果你查看Get-credential的帮助文件,你会发现-Credential参数是位置的,这意味着你不需要输入它。
试试这个
$cred = get-credential -Message "Prompts for username and password"
Enter-PSSession -ComputerName servername -Credential $cred
关于位置参数的一些阅读 https://itknowledgeexchange.techtarget.com/powershell/positional-parameters/