microsoft / EntraExporter

PowerShell module to export a local copy of an Entra (Azure AD) tenant configuration.
https://aka.ms/EntraExporter
MIT License
568 stars 89 forks source link

"Could not find a part of the path" errors when hitting file path length limits #31

Closed SamErde closed 1 year ago

SamErde commented 2 years ago

You may receive the following error[s] when exported JSON file paths are longer than 260 characters:

New-Item : Could not find a part of the path 'C:\Users\UserFolder\Repos\AADExporter\[ I Used My Tenant GUID ]\
OnPremisesPublishingProfiles\ApplicationProxy\ConnectorGroups\[GUID]\Applications\[GUID]\[GUID].json'.
At C:\Program Files\WindowsPowerShell\Modules\AzureADExporter\1.0.957478\Export-AzureAD.ps1:136 char:101
+ ... 00 | Out-File (New-Item -Path "$($parentOutputFileName).json" -Force)
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\Users\...\....json:String) [New-Item], DirectoryNotFoundExce
   ption
    + FullyQualifiedErrorId : NewItemIOError,Microsoft.PowerShell.Commands.NewItemCommand

A workaround to this is to enable long paths via the Windows registry or a GPO setting. Run the following from an elevated PowerShell session and then close PowerShell before trying your export again:

New-ItemProperty `
    -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
    -Name "LongPathsEnabled" `
    -Value 1 `
    -PropertyType DWORD `
    -Force

Credit: @shaunluttin via https://bigfont.ca/enable-long-paths-in-windows-with-powershell/ and https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell.

It might be worth adding this info to the README.

merill commented 1 year ago

Thanks. Have added this to the readme.