Powershell: Using Copy-Item from Linux (Ubuntu 16.04.2) To Windows (2016 Server Core)

Created on 10 Aug 2017  路  12Comments  路  Source: PowerShell/PowerShell

I'm wondering, since SSH remoting from Linux to Windows is available in some form now, if it will be possible eventually to copy files from Linux to Windows.

I've got the remoting to work very nicely following this excellent guide https://github.com/PowerShell/PowerShell/tree/master/demos/SSHRemoting

Steps to reproduce

$session = New-PSSession -HostName remotewinservercore2016.azure.com -UserName foo

Copy-Item -Path ./foo.text -Destination C:\users\foo\ -Verbose -ToSession $session

Expected behavior


Actual behavior

Copy-Item : Unable to load DLL 'api-ms-win-core-file-l1-2-2.dll': The specified module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E)
At line:1 char:1
+ Copy-Item -Path ./Downloads/com.cer -Destination C:\users\op ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], DllNotFoundException
    + FullyQualifiedErrorId : System.DllNotFoundException,Microsoft.PowerShell.Commands.CopyItemCommand

Environment data

> $PSVersionTable

Name                           Value                                                                                                                                                      
----                           -----                                                                                                                                                      
PSVersion                      6.0.0-beta                                                                                                                                                 
PSEdition                      Core                                                                                                                                                       
GitCommitId                    v6.0.0-beta.5                                                                                                                                              
OS                             Linux 4.4.0-89-generic #112-Ubuntu SMP Mon Jul 31 19:38:41 UTC 2017                                                                                        
Platform                       Unix                                                                                                                                                       
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                    
PSRemotingProtocolVersion      2.3                                                                                                                                                        
SerializationVersion           1.1.0.1                                                                                                                                                    
WSManStackVersion              3.0           

Issue-Bug OS-Linux WG-Remoting

Most helpful comment

Please verify it does not work with the latest PS Core version. 馃槂

All 12 comments

Actually, it appears that the file is actually transferred! (I didn't realize this at first, sorry). But the error still occurs.

@PaulHigin Could you please comment the Issue?

This is a known issue where copy-item is referencing non-existent dlls. I don't recall the exact reason but as you see it doesn't prevent the file from being copied. I think this can be fixed fairly easily but has not been high priority. I don't remember if there is an issue tracking this so lets keep this issue open. I'll update the tags.

@PaulHigin Thank you! This must definitely be corrected before 6.0.
Once we remove Windows Dlls from Unix distrib, it may be easier to detect such problems.
/cc @SteveL-MSFT

Still does not work in PowerShell Core 6.0.2 (copy from Windows to Windows over SSH).

Please verify it does not work with the latest PS Core version. 馃槂

Works fine in PowerShell Core 6.1.0 and 6.2.0-preview.1.

It works in PowerShell Core 6.1.0 when I copy a file from client (Windows 10) to both servers (Windows Server 2012 R2).

However, it crashes when I copy a file between the 2 servers.

PS C:\TEMP> $s = New-PSSession -UserName Administrator -HostName example.com
PS C:\TEMP> Copy-Item .\CopyItem.txt C:\temp -ToSession $s
Copy-Item : Unable to load DLL 'api-ms-win-core-file-l1-2-2.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
At line:1 char:1
+ Copy-Item .\CopyItem.txt C:\temp -ToSession $s
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Copy-Item], DllNotFoundException
+ FullyQualifiedErrorId : System.DllNotFoundException,Microsoft.PowerShell.Commands.CopyItemCommand

Client

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

Server A and Server B

> $PSVersionTable

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

I will try to install the preview version tomorrow.

Does not work with the 6.2.0-preview.1 version.

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.0-preview.1
PSEdition                      Core
GitCommitId                    6.2.0-preview.1
OS                             Microsoft Windows 6.3.9600
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


PS C:\> $s = New-PSSession -UserName Administrator example.com
PS C:\> Invoke-Command -Session $s -ScriptBlock { $PSVersionTable }

Name                           Value
----                           -----
PSRemotingProtocolVersion      2.3
GitCommitId                    6.2.0-preview.1
OS                             Microsoft Windows 6.3.9600
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
SerializationVersion           1.1.0.1
PSEdition                      Core
WSManStackVersion              3.0
Platform                       Win32NT
PSVersion                      6.2.0-preview.1


PS C:\> Copy-Item C:\TEMP\CopyItem.txt C:\TEMP\ -ToSession $s
Copy-Item : Unable to load DLL 'api-ms-win-core-file-l1-2-2.dll' or one of its d
ependencies: The specified module could not be found. (Exception from HRESULT: 0
x8007007E)
At line:1 char:1
+ Copy-Item C:\TEMP\CopyItem.txt C:\TEMP\ -ToSession $s
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Copy-Item], DllNotFoundException
+ FullyQualifiedErrorId : System.DllNotFoundException,Microsoft.PowerShell.Comma
nds.CopyItemCommand

PS C:\> Remove-PSSession $s
PS C:\>

@SteveL-MSFT Do you want being self-assigned?

@dnataraj can you check if you have all the .Net Core pre-reqs installed? https://docs.microsoft.com/en-us/dotnet/core/windows-prerequisites?tabs=netcore21

@SteveL-MSFT

Server A:

PS C:\Windows\system32> Get-HotFix KB2999226

Source        Description      HotFixID      InstalledBy          InstalledOn
------        -----------      --------      -----------          -----------
AAAAAAA-AA... Update           KB2999226     AAAAAAA-AAAAAAA\I... 9/16/2016 12:00:00 AM

PS C:\Windows\system32> dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
PS C:\Windows\system32> dotnet --list-sdks
2.1.104 [C:\Program Files\dotnet\sdk]
2.1.200 [C:\Program Files\dotnet\sdk]
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.301 [C:\Program Files\dotnet\sdk]
2.1.302 [C:\Program Files\dotnet\sdk]
2.1.402 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]

Server B:

PS C:\Windows\system32> Get-HotFix KB2999226

Source        Description      HotFixID      InstalledBy          InstalledOn
------        -----------      --------      -----------          -----------
BBBBBBB-BB... Update           KB2999226     BBBBBBB-BBBBBBB\G... 8/18/2016 12:00:00 AM

PS C:\Windows\system32> dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App
Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
PS C:\Windows\system32> dotnet --list-sdks
PS C:\Windows\system32>

I will check other updates later.

Was this page helpful?
0 / 5 - 0 ratings