Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.1 kB
2
Indexable
Never
# Function to get the maximum path length
function Get-MaximumPathLength {
    try {
        # Path to the registry setting for long paths
        $registryPath = "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem"
        $registryName = "LongPathsEnabled"

        # Check if long paths are enabled
        $longPathsEnabled = (Get-ItemProperty -Path $registryPath -Name $registryName -ErrorAction SilentlyContinue).LongPathsEnabled

        # Determine the maximum path length
        if ($longPathsEnabled -eq 1) {
            $maxPathLength = 32767
            Write-Host "Long paths are enabled. Maximum path length is $maxPathLength characters." -ForegroundColor Green
        }
        else {
            $maxPathLength = 260
            Write-Host "Long paths are not enabled. Maximum path length is $maxPathLength characters." -ForegroundColor Yellow
        }
    }
    catch {
        Write-Host "An error occurred while retrieving the maximum path length: $_" -ForegroundColor Red
    }
}

# Run the function
Get-MaximumPathLength

# Pause the script to see the result
Pause
Leave a Comment