当我使用Invoke-command运行脚本时,无法将驱动器映射到工作组计算机。我正在使用Invoke-command连接到一个工作组计算机,尝试映射驱动器。我能够连接到该计算机,但无法映射驱动器。
我尝试了以下选项:
我尝试使用
net use $driveName $ShareLocation $Password /u:$Username
出现错误:
System error 1312 has occurred. + CategoryInfo : NotSpecified: (System error 1312 has occurred.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError + PSComputerName : 10.125.160.132 A specified logon session does not exist. It may already have been terminated.
我尝试过使用
$net.MapNetworkDrive($driveName, $ShareLocation, $false, $Username, $Password);
New-PSDrive -Name K -PSProvider FileSystem -Scope Global -Root $ShareLocation -Credential $Credential -Persist
获取错误:
A specified logon session does not exist. It may already have been terminated. + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
当我直接在远程机器上测试代码时,它可以正常工作。
我还尝试在两台机器上启用CredSSP并使用Invoke-command命令,但没有帮助。