PowerShell icon indicating copy to clipboard operation
PowerShell copied to clipboard

UNC/CIFS Share paths not working in linux version?

Open thebtm opened this issue 6 years ago • 22 comments

Steps to reproduce

#linux powershell
PS /> Set-Location //server/folder/                     
Set-Location : Cannot find path '//server/folder/' because it does not exist.
At line:1 char:1
+ Set-Location //server/folder/
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (//server/folder/:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
 
PS /> Set-Location \\server\folder\
Set-Location : Cannot find path '\\server\folder\' because it does not exist.
At line:1 char:1
+ Set-Location \\server\folder\
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (\\server\folder\:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

Expected behavior

#windows powershell 6.0
PS C:\Program Files\PowerShell\6.0.2> Set-Location \\server\folder\
PS Microsoft.PowerShell.Core\FileSystem::\\server\folder>
PS Microsoft.PowerShell.Core\FileSystem::\\server\folder> ls


    Directory: \\server\folder

PS Microsoft.PowerShell.Core\FileSystem::\\server\folder>

Actual behavior

its not connecting to the UNC/CIFS share on the linux version of powershell

Environment data

My CentOS 7 box does have the cifs-util installed to perform a mount -t cifs installed andIi can mount locally but looking to see if we can just open the connection to the share without having to mount anything.

#bash
[root@centos7 powershell]# dnf list installed | grep cifs
cifs-utils.x86_64                       6.2-10.el7                       @System
#powershell
> $PSVersionTable

PS /> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.1
PSEdition                      Core
GitCommitId                    v6.1.0-preview.1
OS                             Linux 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


PS Microsoft.PowerShell.Core\FileSystem::\\server\folder> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.2
PSEdition                      Core
GitCommitId                    v6.0.2
OS                             Microsoft Windows 10.0.14393
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

thebtm avatar Apr 11 '18 19:04 thebtm

Think this is known issue posted sometime ago. I think it was posted as an issue with the New-PSDrive cmdlet no able to work with CIFS settings or something.
:)

MaximoTrinidad avatar Apr 11 '18 19:04 MaximoTrinidad

I wasn't able to find that issue or i would have posted there. your welcome to combine the issues. I have a PowerShell script I tried running on the Linux version that pointed didn't save the file into the network share like it suppose.

thebtm avatar Apr 11 '18 19:04 thebtm

I'm looking for it because I mention it long time ago. I'm using CIFS shared folders outside of PowerShell. :)

MaximoTrinidad avatar Apr 11 '18 19:04 MaximoTrinidad

Well! I guess I never did post nor comment about it.
:(

This feature could be useful if you can use the New-PSDrive to connect to an existing Shared folder.

MaximoTrinidad avatar Apr 11 '18 19:04 MaximoTrinidad

Well! Circling back to this issue.

I notice this issue has been open since 2016 from the original issue which has been closed without resolution. (https://github.com/PowerShell/PowerShell/issues/1409)

Any idea now that we are reaching RC status? This should have been fixed by now. :)

MaximoTrinidad avatar May 13 '18 14:05 MaximoTrinidad

So, why not allowing the following: (At least for "smbfs")

New-PSDrive -Name "Linux/UnixfolderToMount" -Root "\\Server\ShareFolder" -PSProvider "smb"  -Credentials UserID@Hostname

:)

MaximoTrinidad avatar May 13 '18 14:05 MaximoTrinidad

I tried using New-PSDrive with -Root '\\hostname\sharename' on CentOS 7. Same error message.

oskarm93 avatar Jul 18 '18 17:07 oskarm93

Spongebob-AFewMomentsLater

midacts avatar Jun 19 '19 15:06 midacts

I'm currently trying to make our existing PowerShell 5 scripts compatible with PowerShell Core/6 and have ran into this issue on Mac. Windows PowerShell Core is able to connect to UNC (Samba) paths, but Mac PowerShell Core 6.2 cannot. It appears this issue has either been forgotten or is just not a priority. Has there been any work done to make this work?

keithallenjackson avatar Jun 25 '19 19:06 keithallenjackson

@SteveL-MSFT I pinged Chris Bergmeister in slack to see if this might be something that would be resolved in PS 7. He suggested I ping you on this issue to ask.

My team is looking to leverage PS 7 on linux to migrate our PS 5.1 code and build servers over to PS 7 running on Linux. This is one of the issues I've ran into hindering us from migrating off of PS 5.1.

midacts avatar Jul 02 '19 15:07 midacts

@Midacts the problem is that the Windows file system inherently handles SMB/CIFS paths so there's no special handling by PowerShell. Linux/macOS does not. One option is to leverage smbclient on Linux. Or install OpenSSH on Windows and use SCP or SFTP across all your operating systems.

SteveL-MSFT avatar Jul 05 '19 19:07 SteveL-MSFT

It makes sense. I've used smbclient on linux machines before. Thanks for the reply.

midacts avatar Jul 05 '19 23:07 midacts

My team uses PowerShell on Windows to help manage our CI tasks. We are experimenting with it on Linux now with PS7. Not being able to use New-PsDrive on Linux to access a smb path sucks. Relatedly we noticed Restart-Computer doesn't work on Linux either.

Is there an easy way to determine the PowerShell commands that work on Linux or the limitations of the commands on different operating systems?

I'm looking at the help documentation for New-PSDrive and Restart-Computer. Neither of these commands mention this necessary information. Conceivable one could guess Restart-Computer won't work on Linux by reading the Notes section of the documentation...

soul4soul avatar Sep 24 '19 13:09 soul4soul

smbclient seems like a suitable workaround if you need to perform simple file transfers.

What about cmdlets like New-PSRepository? I'm not seeing a clear way to create repos or publish modules to a UNC/CIFS path unless you are on Windows.

Use smb (server) to mount those paths ahead of time?

Christophoclese avatar Sep 24 '19 16:09 Christophoclese

It may be possible to enable this by calling out to smbclient but would require that command to be installed.

SteveL-MSFT avatar Oct 21 '19 21:10 SteveL-MSFT

So the year has passed without any implementation

Molochnikov avatar Nov 25 '20 16:11 Molochnikov

Just ran into this now as well. I have been using Powershell Core 7 as a way to get my scripts to run cross-platform, so this is a bit of a snag. :(

MunchyYDL avatar Dec 22 '20 16:12 MunchyYDL

To bad this isnt implemented.. needed this for copying some file from a share in linux and to some work with it. now i need more tooling

larsmaes avatar Mar 03 '21 19:03 larsmaes

On top of it being very unfortunate that this ability doesn't exist for the mac and linux versions, but there is nary a mention of this in the documentation for New-PSDrive. We were moving forward with an implementation that used powershell on Linux and one of our use cases is mounting temporary windows shares. Imagine my surprise that it doesn't think any of our shares exist.

andyedison avatar Apr 14 '21 13:04 andyedison

And now we're yet another year later. No mention of a fix, and nothing in the documentation to say it doesn't work for non-windows platforms.

godeater avatar Apr 07 '22 22:04 godeater

what's the point of bringing powershell to linux if you can't even use literally the most common task for system administrators to do inside of a org.

Even if it is a supper janky and very slow method of copying files, it would be great. having nothing is a joke.

LinuxBoi7777 avatar Oct 14 '22 00:10 LinuxBoi7777

OK i figured out a way to copy items from the powershell 7.2 linux to a windows smb share but it's hacky. Better than no option at all.

#wnsuring windows drive is mapped to linux
if(test-path "/mnt/win_share"){
     echo "Share drive exists, i will map to letter D"
     $D = "/mnt/win_share"
}else{
     #running bash command inside of a .ps1 file
     "mount -t cifs -o [email protected],password=123 //10.151.150.35/smb_share /mnt/win_share" | bash
     $D = "/mnt/win_share"
}

#query items to copy
$Files2Copy = ((get-childitem /home/administrator)) | where-object{$_.LastWriteTime -lt ((get-date).AddDays(-30))}

#copy items command
foreach($file in $Files2Copy){
  copy-item ($file).FullName $D
}

"umount /mnt/win_share" | bash

basically we are piping a command line argument string into bash. This is not the intended way of normally doing things since new-psdrive is off the table, but at least we can get some milage.

I think the default behavior to map a drive in linux should do a synthetic mapping of the /mnt drive, just so system administrators don't need to research for hours to come up with a solution.

LinuxBoi7777 avatar Oct 14 '22 01:10 LinuxBoi7777

Any updates?

hamaney avatar Feb 18 '23 02:02 hamaney

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.