philippe27
Goto Top

SharePoint überlange Dateinamen und Pfade

Hallo

Ich hatte eine Anfrage mit bestehendem SharePoint und Problemen mit der OneDrive Synchronisierung dessen Ordners über verschiedene Computer hinweg.

Bei der Fehleranalyse ist mir relativ schnell aufgefallen das diverse OneDrive Instanzen die Meldung mit "zu langer Dateipfad ..." bringen.
Leider hat über Monate bzw. vielleicht Jahre hinweg, eine externe Consulter Gruppe, Kundenanalysen mit Word, Excel, PowerPoint usw. Dateien, in einer zwar sauber Organisierten, aber endlos tiefen Ordnerstruktur abgelegt.
Als würde nur schon der Pfad fast endlos sein, so enthalten unzählige dieser Dateien einen sehr sehr langen Dateinamen.

Ein Beispiel:
Eine Word Datei liegt in 11 Unterordner (jeder Ordner min. 12 Zeichen) und hat einen Dateinamen mit 143 Zeichen!
Gemäss der Kundin könnte es gegen 2'500 solcher Dateien geben und die Sync Probleme waren seit mehr als 1 Jahr bekannt face-sad

Nun muss ich irgendwie helfen und dachte zuerst an eine Aufschlüsselung aller Dateinamen mit zB. Pfadlänge >128 Zeichen.
Danach müsste ich selektiv vielleicht nach einem Dateinamensmuster (Ich kann nicht sagen ob es derzeit eine Dateinamens Struktur gibt), die Dateien Anhangd eines Musters kürzen.

Auf der Suche nach einer ersten Software, bin ich auf TreeSize von JAM Software gestosen, aber diese möchte scheinbar nicht OneDrive Ordner scannen und mit dem SharePoint Pfad bringt er mir auch keine Ergebnise.

Habt Ihr eine Idee, wie ich da sinnvoll helfen könnte?

Danke und Gruss
Philippe

Content-Key: 62086212870

Url: https://administrator.de/contentid/62086212870

Printed on: April 28, 2024 at 11:04 o'clock

Member: mbehrens
mbehrens Dec 13, 2023 at 21:04:04 (UTC)
Goto Top
Zitat von @Philippe27:

Auf der Suche nach einer ersten Software, bin ich auf TreeSize von JAM Software gestosen, aber diese möchte scheinbar nicht OneDrive Ordner scannen und mit dem SharePoint Pfad bringt er mir auch keine Ergebnise.

Über die Microsoft Graph API kann auf solche Informationen zugegriffen werden.
Member: Philippe27
Philippe27 Dec 14, 2023 at 11:58:30 (UTC)
Goto Top
Danke, ich kenne die Graph API bisher kaum.
Hast du ein Tutorial oder einen Link wo dieses eine Thema beschrieben wäre?
Member: mbehrens
mbehrens Dec 14, 2023 at 12:38:03 (UTC)
Goto Top
Zitat von @Philippe27:

Danke, ich kenne die Graph API bisher kaum.
Hast du ein Tutorial oder einen Link wo dieses eine Thema beschrieben wäre?

Das steht alles in der Dokumentation von Microsoft, u. a.:

Overview of Microsoft Graph
Working with SharePoint sites
Mitglied: 8030021182
8030021182 Dec 14, 2023 updated at 12:51:34 (UTC)
Goto Top
Umgefähr so
# Install module
if (-not (Get-Module -Name Microsoft.Graph.Authentication -ListAvailable)) {
    Install-Module -Name Microsoft.Graph.Authentication -Force -AllowClobber -Scope CurrentUser
}
# Import module
Import-Module Microsoft.Graph.Authentication -Force

# Register an application in Azure AD and grant permissions
# https:{{comment_single_line_double_slash:0}}

# Set the application and tenant details
$appId = "YOUR_APP_ID"  
$tenantId = "YOUR_TENANT_ID"  
$clientSecret = "YOUR_CLIENT_SECRET"  
$scopes = "Files.Read.All"  
# OneDrive ID
$userOneDriveId = "YOUR_ONEDRIVE_ID"  

$authParams = @{
    TenantId     = $tenantId
    ClientId     = $appId
    ClientSecret = $clientSecret
    Scope        = $scopes
}
$graphToken = Get-MgAccessToken @authParams

function Get-LongFilePathsRecursively {
    param (
        [string]$token,
        [string]$userId,
        [string]$folderPath = "/"  
    )
    $headers = @{
        Authorization = "Bearer $token"  
    }
    $endpoint = "https://graph.microsoft.com/v1.0/users/$userId/drive/root:$($folderPath)/children"  
    $files = Invoke-RestMethod -Uri $endpoint -Headers $headers -Method Get

    foreach ($file in $files.value) {
        if ($file.folder -ne $null) {
            # If the item is a folder, recursively call the function
            Get-LongFilePathsRecursively -token $token -userId $userId -folderPath "$($folderPath)$($file.name)"  
        } elseif ($file.fileSystemInfo.path.length -gt 250) {
            $file.fileSystemInfo.path
        }
    }
}

$longPaths = Get-LongFilePathsRecursively -token $graphToken -userId $userOneDriveId
Write-Output "Pfade mit mehr als 250 Zeichen:"  
$longPaths
https://learn.microsoft.com/de-de/powershell/module/microsoft.graph.file ...
https://learn.microsoft.com/en-us/graph/api/resources/onedrive?view=grap ...

Gruß Katrin
Member: Philippe27
Philippe27 Dec 19, 2023 at 16:25:17 (UTC)
Goto Top
Zitat von @8030021182:

Umgefähr so
# Install module
if (-not (Get-Module -Name Microsoft.Graph.Authentication -ListAvailable)) {
    Install-Module -Name Microsoft.Graph.Authentication -Force -AllowClobber -Scope CurrentUser
}
# Import module
Import-Module Microsoft.Graph.Authentication -Force

# Register an application in Azure AD and grant permissions
# https:{{comment_single_line_double_slash:0}}

# Set the application and tenant details
$appId = "YOUR_APP_ID"  
$tenantId = "YOUR_TENANT_ID"  
$clientSecret = "YOUR_CLIENT_SECRET"  
$scopes = "Files.Read.All"  
# OneDrive ID
$userOneDriveId = "YOUR_ONEDRIVE_ID"  

$authParams = @{
    TenantId     = $tenantId
    ClientId     = $appId
    ClientSecret = $clientSecret
    Scope        = $scopes
}
$graphToken = Get-MgAccessToken @authParams

function Get-LongFilePathsRecursively {
    param (
        [string]$token,
        [string]$userId,
        [string]$folderPath = "/"  
    )
    $headers = @{
        Authorization = "Bearer $token"  
    }
    $endpoint = "https://graph.microsoft.com/v1.0/users/$userId/drive/root:$($folderPath)/children"  
    $files = Invoke-RestMethod -Uri $endpoint -Headers $headers -Method Get

    foreach ($file in $files.value) {
        if ($file.folder -ne $null) {
            # If the item is a folder, recursively call the function
            Get-LongFilePathsRecursively -token $token -userId $userId -folderPath "$($folderPath)$($file.name)"  
        } elseif ($file.fileSystemInfo.path.length -gt 250) {
            $file.fileSystemInfo.path
        }
    }
}

$longPaths = Get-LongFilePathsRecursively -token $graphToken -userId $userOneDriveId
Write-Output "Pfade mit mehr als 250 Zeichen:"  
$longPaths
https://learn.microsoft.com/de-de/powershell/module/microsoft.graph.file ...
https://learn.microsoft.com/en-us/graph/api/resources/onedrive?view=grap ...

Gruß Katrin

Vielen Dank für die Hilfe, aber vielleicht mache ich etwas falsch.
Wenn ich dein Vorschlag inkl. Microsoft Entra ID's versuche auszuführen, erhalte ich folgenden Fehlercode:
Get-MgAccessToken : Die Benennung "Get-MgAccessToken" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines ausführbaren   
Programms erkannt.

Wenn ich nach der Cmdlet Funktion "Get-MgAccessToken" suche, finde ich keine hilfreichen Informationen dazu.
Authentifizieren kann ich mich und es scheint als wären die Microsoft Graph Module geladen.

Eine Idee woran es liegen kann?

Danke und Gruss
Philippe