Home > OS >  Powershell dealing with long path works on one system , but not the other
Powershell dealing with long path works on one system , but not the other

Time:04-04

Not working system

Path starts with \\?\C:\Users...

copy-item -path $sf -Destination $tf

I get the bellow errors message

copy-item : Illegal characters in path

I remove the leading \\?\ it will stop complaining.

Also an issue with Compress Archive I call Compress-Archive -Path "\\?\$($RootDir...

It returns no errors , but no zip file get created.

This is win 11 21H2

$PSVersionTable

Name                           Value                                                         
----                           -----                                                         
PSVersion                      5.1.22000.282                                                 
PSEdition                      Desktop                                                       
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                       
BuildVersion                   10.0.22000.282                                                
CLRVersion                     4.0.30319.42000                                               
WSManStackVersion              3.0                                                           
PSRemotingProtocolVersion      2.3                                                           
SerializationVersion           1.1.0.1                                                       

On the system this works on

This is win 10 21H2

$PSVersionTable

Name                           Value                                                                                       
----                           -----                                                                                       
PSVersion                      5.1.19041.1320                                                                              
PSEdition                      Desktop                                                                                     
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                     
BuildVersion                   10.0.19041.1320                                                                             
CLRVersion                     4.0.30319.42000                                                                             
WSManStackVersion              3.0                                                                                         
PSRemotingProtocolVersion      2.3                                                                                         
SerializationVersion           1.1.0.1                                                   

CodePudding user response:

The reply by zett42 is the answer

Enable long paths system-wide, so you no longer need to deal with prehistoric \?\ prefix, instead you can just use normal paths: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-1607-and-later – zett42

  • Related