How to repair your Sitecore instance in seconds

Another day and another PS Script for Sitecore dinosaurs in pre-docker age. This one does a basic repair of your instance without disturbing your custom dlls/configs. If you backed-up your webroot folders maybe this doesn't hold water but most of the times we forget to do it at least the first time! Useful in scenarios wherein you messed up your local environment dlls/configs or folder system - Think of those Object reference ysod errors. Would work better with a VS code publish to reset your local instance back to working condition. The main advantage is, you don't need to manually copy over folders/files from scwdp file. This one auto-downloads the xp0 developer zip file and repairs the structure of your local instance.



This script works for 9.x and 10.x instances. Based on size of a file in bin folder, replaces correct version of file if there is a different file (size) version deployed to web root folders. Size comparison is applicable only for bin folder and not others. Note that the folder can be parameterised but could give unexpected results if something like App_Config is passed.  You could also provide a dummy prefix and this script will dump all files from scwdp to the concerned folders.

Testing:

1. Delete Sitecore.Kernel.dll from a 9.3 instance and you have this ysod:

Server Error in '/' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0234: The type or namespace name 'UserProfile' does not exist in the namespace 'Sitecore.Security' (are you missing an assembly reference?)

Source Error:

Line 283:      </providers>
Line 284:    </roleManager>
Line 285:    <profile defaultProvider="sql" enabled="true" inherits="Sitecore.Security.UserProfile, Sitecore.Kernel">
Line 286:      <providers>
Line 287:        <clear/>

Source File: c:\inetpub\wwwroot\sc93insc.dev.local\Web.config    Line: 285






Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.9032.0


2. Next, run the PS repair script as follows:

.\Repair_Sitecore_Script.ps1 -SitePrefix sc93in

3. The script downloads the zip for the version from SDN if not existing, unzips the same and uses it as reference to check the web site's file system and repair in case there is a missing file(s) or folder(s). If the reference folder is present, uses the same for cross-checking in the consequent runs:


4. File system structure built by the script:



5. In case file system is fine, provides relevant message:



Constraints:

- Currently works for xp0 topology but topology can be parameterised

- if files like ConnectionStrings.config are deleted, wouldn't be able to repair unless VS publish complements in some way


Comments