我正在尝试对具有“。\”的计算机运行远程命令。
当我使用get-credentials尝试凭据并将它们存储到文件中时,我不允许这样做。 当我尝试使用
时$Username = -join($env:COMPUTERNAME,'\<user_name>')
$Password = '<password>'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
Invoke-Command -ComputerName <computer_name> -Authentication Kerberos -Credential $Cred {Get-WmiObject -Class Win32_LogicalDisk}
我收到以下错误
Connecting to remote server failed with the following error message : WinRM cannot process the request. The following error occured while using Kerberos authenticati
on: There are currently no logon servers available to service the logon request.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are specified.
-Kerberos accepts domain user names, but not local user names.
-The Service Principal Name (SPN) for the remote computer name and port does not exist.
-The client and remote computers are in different domains and there is no trust between the two domains.
After checking for the above issues, try the following:
-Check the Event Viewer for events related to authentication.
-Change the authentication method; add the destination computer to the WinRM TrustedHosts configuration setting or use HTTPS transport.
Note that computers in the TrustedHosts list might not be authenticated.
-For more information about WinRM configuration, run the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (:) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionStateBroken
但是当我做一个mstsc并使用相同的凭据时,它可以工作。
请让我了解一下。
答案 0 :(得分:0)
$env:COMPUTERNAME
您的 计算机名称!
想象一下,我正在使用ComputerA,并希望以ComputerB上的本地用户身份连接到ComputerB。
您的代码目前正在尝试以ComputerA\Username
身份进行连接,这在ComputerB上不存在!
答案 1 :(得分:0)
您可以尝试使用以下语法传递用户名吗?
$Username = -join('Localhost','\<user_name>')