指定的登录会话不存在。它可能已经被终止

Ili*_*yas 7 powershell remote-server

当我使用调用命令运行脚本时,无法将驱动器映射到工作组机器。我正在使用 Invoke-command 连接到工作组机器,并在那里尝试映射驱动器。我能够连接到机器,但无法映射驱动器。我尝试过以下选项:

我试过使用

net use $driveName $ShareLocation $Password /u:$Username
Run Code Online (Sandbox Code Playgroud)

获取错误:

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.
Run Code Online (Sandbox Code Playgroud)

我试过使用

$net.MapNetworkDrive($driveName, $ShareLocation, $false, $Username, $Password);
New-PSDrive -Name K -PSProvider FileSystem -Scope Global -Root $ShareLocation -Credential $Credential -Persist
Run Code Online (Sandbox Code Playgroud)

获取错误:

A specified logon session does not exist. It may already have been terminated. + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException 
Run Code Online (Sandbox Code Playgroud)

当我直接在远程机器上尝试此代码时,这工作正常。

我还尝试在机器上启用 CredSSP 并使用 Invoke-command。它没有帮助