windowspowershellpowershell-remotingwinrmmapped-drive

Remote Powershell: Mappped Network device shows status unavailable when checked from remote machine


The machine with which I am running these PowerShell commands is a Ubuntu 18.04 machine, but this behavior persists when running from another windows machine also. I was trying to remotely execute a command to copy a file from the C:\ to a mapped network device \\name\share\ through the Invoke-Command cmdlet, but I am constantly getting this error:

PS /home/appadmin> Invoke-Command -ComputerName x.x.x.x -ScriptBlock {Copy-Item -Path C:\Directory -Destination \\name\share\ -Recurse -Force} -Credential $cred -Authentication Negotiate
The path is not of a legal form.
+ CategoryInfo          : InvalidArgument: (\\name\share\:String) [Copy-Item], ArgumentException
+ FullyQualifiedErrorId : CreateDirectoryArgumentError,Microsoft.PowerShell.Commands.CopyItemCommand
+ PSComputerName        : x.x.x.x

The handle is invalid.
+ CategoryInfo          : WriteError: (File.vhdx:FileInfo) [Copy-Item], IOException
+ FullyQualifiedErrorId : CopyDirectoryInfoItemIOError,Microsoft.PowerShell.Commands.CopyItemCommand
+ PSComputerName        : x.x.x.x

PS /home/username>

But the same copying (with the Copy-Item command)is successful from the windows host itself.

Then after further debugging, I came to know that the status of the network device from the remote Ubuntu machine is Unavailable

PS /home/username> Invoke-Command -ComputerName x.x.x.x -ScriptBlock { net use } -Credential $cred -Authentication Negotiate
New connections will be remembered.
Status       Local     Remote                    Network

-------------------------------------------------------------------------------
Unavailable  Y:        \\name\share         Microsoft Windows Network
The command completed successfully.

PS /home/appadmin>

But the network device status from the windows host itself is showing OK

PS C:\Users\Administrator> net use
New connections will be remembered.
Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK           Y:        \\name\share         Microsoft Windows Network
The command completed successfully.

PS C:\Users\Administrator>

I have already looked at the permission of the network device and there is no problem there. And it is also not a Double Hop issue.

What should I do to make the network device status as OK from the remote machine, so that I can access the mapped network device \name\share? Any help appreciated


Solution

  • I don't know if anyone has encountered this issue or not. But after a lot of searching finally got it resolved after I gave the Fully Qualified Domain Name (FQDN) "\\name.name2.local\share\" instead of "\\name\share\". It seems that the Remote Powershell commands appreciate the use of FQDN otherwise it won't work as required. Hope this helps