远程 powershell 命令在 Windows 10 目标上失败

远程 powershell 命令在 Windows 10 目标上失败

我想连接到 Windows 10 计算机并使用 powershell 脚本运行远程命令。在 Windows 10 计算机上运行的脚本如下所示

$RemoteMachine = "10.1.1.50"
$vcenter_server ="10.1.1.2"

Set-Item WSMan:\localhost\Client\TrustedHosts -Value $RemoteMachine -force

$Username = 'user'
$Password = ' '
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

Invoke-Command -ComputerName $RemoteMachine -Credential $Cred `
               -ScriptBlock { diskpart /s c:\diskman.txt }

但是,输出显示机器无法访问,而 ping 命令工作正常。

[10.1.1.50] Connecting to remote server 10.1.1.50 failed with the following error message : WinRM cannot complete the operation. 
Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception 
for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles 
limits access to remote computers within the same local subnet. For more information, see the about_Remote_Troubleshooting Help 
topic.
    + CategoryInfo          : OpenError: (10.1.1.50:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken



PS C:\Users\user> ping 10.1.1.50

Pinging 10.1.1.50 with 32 bytes of data:
Reply from 10.1.1.50: bytes=32 time<1ms TTL=128

有什么办法可以找到问题的根源吗?

相关内容