murp

moveiisroot

Mar 2nd, 2023
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.16 KB | Software | 0 0
  1. REM PLEASE BE AWARE: SERVICING (I.E. HOTFIXES AND SERVICE PACKS) WILL STILL REPLACE FILES
  2. REM IN THE ORIGINAL DIRECTORIES. THE LIKELIHOOD THAT FILES IN THE INETPUB DIRECTORIES HAVE
  3. REM TO BE REPLACED BY SERVICING IS LOW BUT FOR THIS REASON DELETING THE ORIGINAL DIRECTORIES
  4. REM IS NOT POSSIBLE.
  5.  
  6. @echo off
  7. IF "%1" == "" goto err
  8. setlocal
  9. set MOVETO=%1:\
  10.  
  11. REM simple error handling if drive does not exist or argument is wrong
  12. IF NOT EXIST %MOVETO% goto err
  13.  
  14. REM Backup IIS config before we start changing config to point to the new path
  15. %windir%\system32\inetsrv\appcmd add backup beforeRootMove
  16.  
  17.  
  18. REM Stop all IIS services
  19. iisreset /stop
  20.  
  21. REM Copy all content
  22. REM /O - copy ACLs
  23. REM /E - copy sub directories including empty ones
  24. REM /I - assume destination is a directory
  25. REM /Q - quiet
  26.  
  27. REM echo on, because user will be prompted if content already exists.
  28. echo on
  29. xcopy %systemdrive%\inetpub %MOVETO%inetpub /O /E /I /Q
  30. @echo off
  31. REM Move AppPool isolation directory
  32. reg add HKLM\System\CurrentControlSet\Services\WAS\Parameters /v ConfigIsolationPath /t REG_SZ /d %MOVETO%inetpub\temp\appPools /f
  33.  
  34. REM Move logfile directories
  35. %windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/sites -siteDefaults.traceFailedRequestsLogging.directory:"%MOVETO%inetpub\logs\FailedReqLogFiles"
  36. %windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/sites -siteDefaults.logfile.directory:"%MOVETO%inetpub\logs\logfiles"
  37. %windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/log -centralBinaryLogFile.directory:"%MOVETO%inetpub\logs\logfiles"
  38. %windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/log -centralW3CLogFile.directory:"%MOVETO%inetpub\logs\logfiles"
  39.  
  40. REM Move config history location, temporary files, the path for the Default Web Site and the custom error locations
  41. %windir%\system32\inetsrv\appcmd set config -section:system.applicationhost/configHistory -path:%MOVETO%inetpub\history
  42. %windir%\system32\inetsrv\appcmd set config -section:system.webServer/asp -cache.disktemplateCacheDirectory:"%MOVETO%inetpub\temp\ASP Compiled Templates"
  43. %windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression -directory:"%MOVETO%inetpub\temp\IIS Temporary Compressed Files"
  44. %windir%\system32\inetsrv\appcmd set vdir "Default Web Site/" -physicalPath:%MOVETO%inetpub\wwwroot
  45. %windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='401'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
  46. %windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='403'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
  47. %windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='404'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
  48. %windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='405'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
  49. %windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='406'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
  50. %windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='412'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
  51. %windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='500'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
  52. %windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='501'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
  53. %windir%\system32\inetsrv\appcmd set config -section:httpErrors /[statusCode='502'].prefixLanguageFilePath:%MOVETO%inetpub\custerr
  54.  
  55. REM Make sure Service Pack and Hotfix Installers know where the IIS root directories are
  56. reg add HKLM\Software\Microsoft\inetstp /v PathWWWRoot /t REG_SZ /d %mOVETO%\inetpub\wwwroot /f
  57. reg add HKLM\Software\Microsoft\inetstp /v PathFTPRoot /t REG_SZ /d %MOVETO%\inetpub\ftproot /f
  58. REM Do the same for x64 directories
  59. if not "%ProgramFiles(x86)%" == "" reg add HKLM\Software\Wow6432Node\Microsoft\inetstp /v PathWWWRoot /t REG_EXPAND_SZ /d %MOVETO%inetpub\wwwroot /f
  60. if not "%ProgramFiles(x86)%" == "" reg add HKLM\Software\Wow6432Node\Microsoft\inetstp /v PathFTPRoot /t REG_EXPAND_SZ /d %MOVETO%inetpub\ftproot /f
  61.  
  62. REM Restart all IIS services
  63. iisreset /start
  64. echo.
  65. echo.
  66. echo ===============================================================================
  67. echo Moved IIS7 root directory from %systemdrive%\ to %MOVETO%.
  68. echo.
  69. echo Please verify if the move worked. If so you can delete the %systemdrive%\inetpub directory.
  70. echo If something went wrong you can restore the old settings via
  71. echo     "APPCMD restore backup beforeRootMove"
  72. echo and
  73. echo     "REG delete HKLM\System\CurrentControlSet\Services\WAS\Parameters\ConfigIsolationPath"
  74. echo You also have to reset the PathWWWRoot and PathFTPRoot registry values
  75. echo in HKEY_LOCAL_MACHINE\Software\Microsoft\InetStp.
  76. echo ===============================================================================
  77. echo.
  78. echo.
  79. endlocal
  80. goto success
  81.  
  82. REM error message if no argument or drive does not exist
  83. :err
  84. echo.
  85. echo New root drive letter required.
  86. echo Here an example how to move the IIS root to the F:\ drive:
  87. echo.
  88. echo MOVEIISROOT.BAT F
  89. echo.
  90. echo.
  91.  
  92. :success
Tags: IIS Move
Add Comment
Please, Sign In to add comment