当我使用Invoke命令运行脚本时,无法将驱动器映射到工作组计算机。我正在使用Invoke命令连接到工作组计算机,并且我正在尝试映射驱动器。我能够连接到机器但无法映射驱动器。以下选项我尝试过:
我试过用
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。它没有帮助
根据文章here at Microsoft“这种行为是设计的”(即使该共享不适用于DFS),可以通过更改Windows策略以允许存储密码来解决,如文章中所述。我一直在尝试按照Bruno Bieri的方式“净使用”,从任务计划程序定期运行的控制台应用程序和任务计划程序属性对话框中包含“不存储密码”复选框;它还说“任务只能访问本地计算机资源”。我无法取消选中它,因为我的组织的Windows策略不允许此更改。
这似乎是“双跳”问题。请尝试按照以下链接进行修复:New-PsDrive Remote copy from DFS share errors: A specified logon session does not exist