A specified logon session does not exist. It may already have been terminated
<p>Unable to Map drive to workgroup machine when I'm running the script using the Invoke-command.
I'm connecting to a workgroup machine using the Invoke-command and there I'm trying to map a drive. I'm able to connect to the machine but unable to Map the drive.
The options below I have tried:</p>

<p>I have tried using</p>

<pre><code>net use $driveName $ShareLocation $Password /u:$Username
</code></pre>

<p>Getting Error:</p>

<pre><code>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.
</code></pre>

<p>I have tried using</p>

<pre><code>$net.MapNetworkDrive($driveName, $ShareLocation, $false, $Username, $Password);
New-PSDrive -Name K -PSProvider FileSystem -Scope Global -Root $ShareLocation -Credential $Credential -Persist
</code></pre>

<p>Getting Error:</p>

<pre><code>A specified logon session does not exist. It may already have been terminated. + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException 
</code></pre>

<p>This is working fine when I'm trying this code directly on the remote machine.</p>

<p>I have also tried enabling CredSSP on both the machine and using Invoke-command. It didn't help</p>