-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggleFileNameLengthLimit.ps1
More file actions
30 lines (24 loc) · 1014 Bytes
/
ToggleFileNameLengthLimit.ps1
File metadata and controls
30 lines (24 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# PowerShell Script to Toggle File Name Length Limit in Windows
param (
[Parameter(Mandatory=$false)]
[switch]$Restore
)
function Enable-LongPathSupport {
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1
Write-Host "Long path support has been enabled."
}
function Disable-LongPathSupport {
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 0
Write-Host "Long path support has been disabled."
}
# Run as Administrator
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning "You do not have Administrator rights to run this script! Please re-run this as an Administrator!"
exit
}
# Toggle the file name length limit based on the command line option
if ($Restore) {
Disable-LongPathSupport
} else {
Enable-LongPathSupport
}