patchWebDAV.ps1 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #Requires -RunAsAdministrator
  2. Param(
  3. [Parameter(Mandatory, HelpMessage="Please provide an alias for 127.0.0.1")][string] $LoopbackAlias
  4. )
  5. # Adds an alias for 127.0.0.1 to the hosts file
  6. function Add-AliasToHost {
  7. param (
  8. [string]$LoopbackAlias
  9. )
  10. $sysdir = [Environment]::SystemDirectory
  11. $hostsFile = "$sysdir\drivers\etc\hosts"
  12. $aliasLine = "127.0.0.1 $LoopbackAlias"
  13. foreach ($line in Get-Content $hostsFile) {
  14. if ($line -eq $aliasLine){
  15. return
  16. }
  17. }
  18. Add-Content -Path $hostsFile -Encoding ascii -Value "`r`n$aliasLine"
  19. }
  20. # Sets in the registry the webclient file size limit to the maximum value
  21. function Set-WebDAVFileSizeLimit {
  22. # Set variables to indicate value and key to set
  23. $RegistryPath = 'HKLM:\SYSTEM\CurrentControlSet\Services\WebClient\Parameters'
  24. $Name = 'FileSizeLimitInBytes'
  25. $Value = '0xffffffff'
  26. # Create the key if it does not exist
  27. If (-NOT (Test-Path $RegistryPath)) {
  28. New-Item -Path $RegistryPath -Force | Out-Null
  29. }
  30. # Now set the value
  31. New-ItemProperty -Path $RegistryPath -Name $Name -Value $Value -PropertyType DWORD -Force | Out-Null
  32. }
  33. # Changes the network provider order such that the builtin Windows webclient is always first
  34. function Edit-ProviderOrder {
  35. $RegistryPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder'
  36. $Name = 'ProviderOrder'
  37. $WebClientString = 'webclient'
  38. $CurrentOrder = (Get-ItemProperty $RegistryPath $Name).$Name
  39. $OrderWithoutWebclientArray = $CurrentOrder -split ',' | Where-Object {$_ -ne $WebClientString}
  40. $WebClientArray = @($WebClientString)
  41. $UpdatedOrder = ($WebClientArray + $OrderWithoutWebclientArray) -join ","
  42. New-ItemProperty -Path $RegistryPath -Name $Name -Value $UpdatedOrder -PropertyType String -Force | Out-Null
  43. }
  44. Add-AliasToHost $LoopbackAlias
  45. Write-Output 'Ensured alias exists in hosts file'
  46. Set-WebDAVFileSizeLimit
  47. Write-Output 'Set WebDAV file size limit'
  48. Edit-ProviderOrder
  49. Write-Output 'Ensured correct provider order'
  50. exit 0