raandree / NTFSSecurity

Managing permissions with PowerShell is only a bit easier than in VBS or the command line as there are no cmdlets for most day-to-day tasks like getting a permission report or adding permission to an item. PowerShell only offers Get-Acl and Set-Acl but everything in between getting and setting the ACL is missing. This module closes the gap.
MIT License
431 stars 61 forks source link

Get-Item2, Get-ChildItem2, Test-Path2 unable to access long paths #54

Closed Regen379 closed 5 years ago

Regen379 commented 5 years ago

NTFSSecurity v4.2.4 is not able to access long paths

Get-Item2 C:\Temp\LongPath\AbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxy\AbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxy\AbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxy.txt get-item2 : Unable to find the specified file.

Get-ChildItem2 C:\Temp\LongPath\AbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxy\AbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxy Get-ChildItem2 : Unable to find the specified file.

Test-Path2 C:\Temp\LongPath\AbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxy\AbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxy\AbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxy.txt False (but it actually exists)

Works properly with NTFSSecurity v4.2.3

Environment: v4.2.3: PowerShell 2.0 on Windows 7 x64 v4.2.4: PowerShell 3.0 on Windows 7 x86 (using PowerShell 3.0 due to failure of v4.2.4 to Import-Module in PowerShell 2.0, which is logged as a separate bug).

raandree commented 5 years ago

The cmdlets support long paths up to about 32k charachters. However, it seems you are hitting a different limit. I cannot even create the file with the long name in the explorer. It seems that a file's name cannot be more than 230 chars.

Regen379 commented 5 years ago

I've worked out that this is not actually a problem with long paths. It seems to be a problem with the version of PowerShell (or maybe .Net?) that is supported by NTFSSecurity v4.2.4. Even short paths fail with PowerShell 3.0 (with .Net 4.0). get-item2 C:\temp\dir1\test.txt get-item2 : Unable to find the specified file.

I think this is related to the other issue I raised "NTFSSecurity v4.2.4 fails on Import-Module in PowerShell 2.0" (https://github.com/raandree/NTFSSecurity/issues/53). https://www.powershellgallery.com/packages/NTFSSecurity/4.2.4 says Minimum PowerShell version = 2.0, but it doesn't work with PowerShell 2.0 or 3.0. I've not tested 4.0, but it seems to be working with 5.0. So the real question is, which version of PowerShell (or maybe .Net?) does NTFSSecurity v4.2.4 require to run properly?

I noticed that NTFSSecurity v4.2.5 has been released. The same problem exists with v4.2.5.

Is there any reason that this can't be compiled with the older version of .Net so that it supports PowerShell 2.0?

raandree commented 5 years ago

Unfortunately I cannot reproduce the issue. The long path cmdlets work for me as expected.

$path = 'D:\LongPath\LongPath1\LongPath2\LongPath3\LongPath4\LongPath5\LongPath6\LongPath7\LongPath8\LongPath9\LongPath10\LongPath11\LongPath12\LongPath13\LongPath14\LongPath15\LongPath16\LongPath17\LongPath18\LongPath19\LongPath20\LongPath21\LongPath22\LongPath23\LongPath24\LongPath25\LongPath26\LongPath27\LongPath28\LongPath29\LongPath30\LongPath31\LongPath32\LongPath33\LongPath34\LongPath35\LongPath36\LongPath37\LongPath38\LongPath39\LongPath40\LongPath41\LongPath42\LongPath43\LongPath44\LongPath45\LongPath46\LongPath47\LongPath48\LongPath49\LongPath50\LongPath51\LongPath52\LongPath53\LongPath54\LongPath55\LongPath56\LongPath57\LongPath58\LongPath59\LongPath60\LongPath61\LongPath62\LongPath63\LongPath64\LongPath65\LongPath66\LongPath67\LongPath68\LongPath69\LongPath70\LongPath71\LongPath72\LongPath73\LongPath74\LongPath75\LongPath76\LongPath77\LongPath78\LongPath79\LongPath80\LongPath81\LongPath82\LongPath83\LongPath84\LongPath85\LongPath86\LongPath87\LongPath88\LongPath89\LongPath90\LongPath91\LongPath92\LongPath93\LongPath94\LongPath95\LongPath96\LongPath97\LongPath98\LongPath99\LongPath100\LongPath101\LongPath102\LongPath103\LongPath104\LongPath105\LongPath106\LongPath107\LongPath108\LongPath109\LongPath110\LongPath111\LongPath112\LongPath113\LongPath114\LongPath115\LongPath116\LongPath117\LongPath118\LongPath119\LongPath120\LongPath121\LongPath122\LongPath123\LongPath124\LongPath125\LongPath126\LongPath127\LongPath128\LongPath129\LongPath130\LongPath131\LongPath132\LongPath133\LongPath134\LongPath135\LongPath136\LongPath137\LongPath138\LongPath139\LongPath140\LongPath141\LongPath142\LongPath143\LongPath144\LongPath145\LongPath146\LongPath147\LongPath148\LongPath149\LongPath150\LongPath151\LongPath152\LongPath153\LongPath154\LongPath155\LongPath156\LongPath157\LongPath158\LongPath159\LongPath160\LongPath161\LongPath162\LongPath163\LongPath164\LongPath165\LongPath166\LongPath167\LongPath168\LongPath169\LongPath170\LongPath171\LongPath172\LongPath173\LongPath174\LongPath175\LongPath176\LongPath177\LongPath178\LongPath179\LongPath180\LongPath181\LongPath182\LongPath183\LongPath184\LongPath185\LongPath186\LongPath187\LongPath188\LongPath189\LongPath190\LongPath191\LongPath192\LongPath193\LongPath194\LongPath195\LongPath196\LongPath197\LongPath198\LongPath199\LongPath200\LongPath201\LongPath202\LongPath203\LongPath204\LongPath205\LongPath206\LongPath207\LongPath208\LongPath209\LongPath210\LongPath211\LongPath212\LongPath213\LongPath214\LongPath215\LongPath216\LongPath217\LongPath218\LongPath219\LongPath220\LongPath221\LongPath222\LongPath223\LongPath224\LongPath225\LongPath226\LongPath227\LongPath228\LongPath229\LongPath230\LongPath231\LongPath232\LongPath233\LongPath234\LongPath235\LongPath236\LongPath237\LongPath238\LongPath239\LongPath240\LongPath241\LongPath242\LongPath243\LongPath244\LongPath245\LongPath246\LongPath247\LongPath248\LongPath249\LongPath250\LongPath251\LongPath252\LongPath253\LongPath254\LongPath255\LongPath256\LongPath257\LongPath258\LongPath259\LongPath260\LongPath261\LongPath262\LongPath263\LongPath264\LongPath265\LongPath266\LongPath267\LongPath268\LongPath269\LongPath270\LongPath271\LongPath272\LongPath273\LongPath274\LongPath275\LongPath276\LongPath277\LongPath278\LongPath279\LongPath280\LongPath281\LongPath282\LongPath283\LongPath284\LongPath285\LongPath286\LongPath287\LongPath288\LongPath289\LongPath290\LongPath291\LongPath292\LongPath293\LongPath294\LongPath295\LongPath296\LongPath297\LongPath298\LongPath299\LongPath300\LongPath301\LongPath302\LongPath303\LongPath304\LongPath305\LongPath306\LongPath307\LongPath308\LongPath309\LongPath310\LongPath311\LongPath312\LongPath313\LongPath314\LongPath315\LongPath316\LongPath317\LongPath318\LongPath319\LongPath320\LongPath321\LongPath322\LongPath323\LongPath324\LongPath325\LongPath326\LongPath327\LongPath328\LongPath329\LongPath330\LongPath331\LongPath332\LongPath333\LongPath334\LongPath335\LongPath336\LongPath337\LongPath338\LongPath339\LongPath340\LongPath341\LongPath342\LongPath343\LongPath344\LongPath345\LongPath346\LongPath347\LongPath348\LongPath349\LongPath350\LongPath351\LongPath352\LongPath353\LongPath354\LongPath355\LongPath356\LongPath357\LongPath358\LongPath359\LongPath360\LongPath361\LongPath362\LongPath363\LongPath364\LongPath365\LongPath366\LongPath367\LongPath368\LongPath369\LongPath370\LongPath371\LongPath372\LongPath373\LongPath374\LongPath375\LongPath376\LongPath377\LongPath378\LongPath379\LongPath380\LongPath381\LongPath382\LongPath383\LongPath384\LongPath385\LongPath386\LongPath387\LongPath388\LongPath389\LongPath390\LongPath391\LongPath392\LongPath393\LongPath394\LongPath395\LongPath396\LongPath397\LongPath398\LongPath399\LongPath400\LongPath401\LongPath402\LongPath403\LongPath404\LongPath405\LongPath406\LongPath407\LongPath408\LongPath409\LongPath410\LongPath411\LongPath412\LongPath413\LongPath414\LongPath415\LongPath416\LongPath417\LongPath418\LongPath419\LongPath420\LongPath421\LongPath422\LongPath423\LongPath424\LongPath425\LongPath426\LongPath427\LongPath428\LongPath429\LongPath430\LongPath431\LongPath432\YXEEAC'

$path.Length

Get-Item2 -Path $path

And the output is:

PS D:\LongPath> . 'C:\Git\DscWorkshop\Lab\Untitled4.ps1' <# script is not saved yet #>
5094

    Directory: D:\LongPath\LongPath1\LongPath2\LongPath3\LongPath4\LongPath5\LongPath6\LongPath7\LongPath8\LongPath9\LongPath10\LongPath11\LongPath12\LongPath13\LongPath14\LongPath15\LongPa
    th16\LongPath17\LongPath18\LongPath19\LongPath20\LongPath21\LongPath22\LongPath23\LongPath24\LongPath25\LongPath26\LongPath27\LongPath28\LongPath29\LongPath30\LongPath31\LongPath32\Long
    Path33\LongPath34\LongPath35\LongPath36\LongPath37\LongPath38\LongPath39\LongPath40\LongPath41\LongPath42\LongPath43\LongPath44\LongPath45\LongPath46\LongPath47\LongPath48\LongPath49\Lo
    ngPath50\LongPath51\LongPath52\LongPath53\LongPath54\LongPath55\LongPath56\LongPath57\LongPath58\LongPath59\LongPath60\LongPath61\LongPath62\LongPath63\LongPath64\LongPath65\LongPath66\
    LongPath67\LongPath68\LongPath69\LongPath70\LongPath71\LongPath72\LongPath73\LongPath74\LongPath75\LongPath76\LongPath77\LongPath78\LongPath79\LongPath80\LongPath81\LongPath82\LongPath8
    3\LongPath84\LongPath85\LongPath86\LongPath87\LongPath88\LongPath89\LongPath90\LongPath91\LongPath92\LongPath93\LongPath94\LongPath95\LongPath96\LongPath97\LongPath98\LongPath99\LongPat
    h100\LongPath101\LongPath102\LongPath103\LongPath104\LongPath105\LongPath106\LongPath107\LongPath108\LongPath109\LongPath110\LongPath111\LongPath112\LongPath113\LongPath114\LongPath115\
    LongPath116\LongPath117\LongPath118\LongPath119\LongPath120\LongPath121\LongPath122\LongPath123\LongPath124\LongPath125\LongPath126\LongPath127\LongPath128\LongPath129\LongPath130\LongP
    ath131\LongPath132\LongPath133\LongPath134\LongPath135\LongPath136\LongPath137\LongPath138\LongPath139\LongPath140\LongPath141\LongPath142\LongPath143\LongPath144\LongPath145\LongPath14
    6\LongPath147\LongPath148\LongPath149\LongPath150\LongPath151\LongPath152\LongPath153\LongPath154\LongPath155\LongPath156\LongPath157\LongPath158\LongPath159\LongPath160\LongPath161\Lon
    gPath162\LongPath163\LongPath164\LongPath165\LongPath166\LongPath167\LongPath168\LongPath169\LongPath170\LongPath171\LongPath172\LongPath173\LongPath174\LongPath175\LongPath176\LongPath
    177\LongPath178\LongPath179\LongPath180\LongPath181\LongPath182\LongPath183\LongPath184\LongPath185\LongPath186\LongPath187\LongPath188\LongPath189\LongPath190\LongPath191\LongPath192\L
    ongPath193\LongPath194\LongPath195\LongPath196\LongPath197\LongPath198\LongPath199\LongPath200\LongPath201\LongPath202\LongPath203\LongPath204\LongPath205\LongPath206\LongPath207\LongPa
    th208\LongPath209\LongPath210\LongPath211\LongPath212\LongPath213\LongPath214\LongPath215\LongPath216\LongPath217\LongPath218\LongPath219\LongPath220\LongPath221\LongPath222\LongPath223
    \LongPath224\LongPath225\LongPath226\LongPath227\LongPath228\LongPath229\LongPath230\LongPath231\LongPath232\LongPath233\LongPath234\LongPath235\LongPath236\LongPath237\LongPath238\Long
    Path239\LongPath240\LongPath241\LongPath242\LongPath243\LongPath244\LongPath245\LongPath246\LongPath247\LongPath248\LongPath249\LongPath250\LongPath251\LongPath252\LongPath253\LongPath2
    54\LongPath255\LongPath256\LongPath257\LongPath258\LongPath259\LongPath260\LongPath261\LongPath262\LongPath263\LongPath264\LongPath265\LongPath266\LongPath267\LongPath268\LongPath269\Lo
    ngPath270\LongPath271\LongPath272\LongPath273\LongPath274\LongPath275\LongPath276\LongPath277\LongPath278\LongPath279\LongPath280\LongPath281\LongPath282\LongPath283\LongPath284\LongPat
    h285\LongPath286\LongPath287\LongPath288\LongPath289\LongPath290\LongPath291\LongPath292\LongPath293\LongPath294\LongPath295\LongPath296\LongPath297\LongPath298\LongPath299\LongPath300\
    LongPath301\LongPath302\LongPath303\LongPath304\LongPath305\LongPath306\LongPath307\LongPath308\LongPath309\LongPath310\LongPath311\LongPath312\LongPath313\LongPath314\LongPath315\LongP
    ath316\LongPath317\LongPath318\LongPath319\LongPath320\LongPath321\LongPath322\LongPath323\LongPath324\LongPath325\LongPath326\LongPath327\LongPath328\LongPath329\LongPath330\LongPath33
    1\LongPath332\LongPath333\LongPath334\LongPath335\LongPath336\LongPath337\LongPath338\LongPath339\LongPath340\LongPath341\LongPath342\LongPath343\LongPath344\LongPath345\LongPath346\Lon
    gPath347\LongPath348\LongPath349\LongPath350\LongPath351\LongPath352\LongPath353\LongPath354\LongPath355\LongPath356\LongPath357\LongPath358\LongPath359\LongPath360\LongPath361\LongPath
    362\LongPath363\LongPath364\LongPath365\LongPath366\LongPath367\LongPath368\LongPath369\LongPath370\LongPath371\LongPath372\LongPath373\LongPath374\LongPath375\LongPath376\LongPath377\L
    ongPath378\LongPath379\LongPath380\LongPath381\LongPath382\LongPath383\LongPath384\LongPath385\LongPath386\LongPath387\LongPath388\LongPath389\LongPath390\LongPath391\LongPath392\LongPa
    th393\LongPath394\LongPath395\LongPath396\LongPath397\LongPath398\LongPath399\LongPath400\LongPath401\LongPath402\LongPath403\LongPath404\LongPath405\LongPath406\LongPath407\LongPath408
    \LongPath409\LongPath410\LongPath411\LongPath412\LongPath413\LongPath414\LongPath415\LongPath416\LongPath417\LongPath418\LongPath419\LongPath420\LongPath421\LongPath422\LongPath423\Long
    Path424\LongPath425\LongPath426\LongPath427\LongPath428\LongPath429\LongPath430\LongPath431\LongPath432

Mode    Inherits             LastWriteTime         Size(M) Name                                                                                                                              
----    --------             -------------         ------- ----                                                                                                                              
d----       True       7/12/2019   3:47 PM   <DIR>         YXEEAC                                                                                                                            

I have done this on PowerShell 5.1 on Windows 10 1903.

raandree commented 5 years ago

Regarding your question why I am not providing this for PowerShell 2 anymore. There is still the older version that should work with no issue on PowerShell 2. Providing the current version for all PowerShell versions is possible of course but it costs time that I do not have right now. However, if the community help with that, I would appreciate this.