PowerShell: Detect and Install SitecoreDockerTools automatically for adding Windows host file entry
Summary: This blog article is about SitecoreDockerTools PowerShell module: one of the pre-requisites required for Sitecore MVP site. If this module is not installed, you will encounter the error listed below.
The scenario explained in this blog article is encountered on a brand-new Windows machine (although I used Windows 11 in this case) as part of installing the Sitecore MVP site. On executing Start-Environment.ps1 without performing any of the initialisation, the Add-HostsEntry command is not recognised. Luckily, I had another machine where Add-HostsEntry was recognised. So, I compared with the same and adjusted the Start-Environment.ps1 code accordingly.
The code-fix here tracks if the necessary pre-requisites: PowerShell repository and module are present. Based on the same, installs the necessary repo and module, if not present. So, this fix and my earlier blog, although is done for Sitecore MVP site, can be generally useful for all website instances running on Sitecore Docker!
Note that although Remove-HostsEntry is part of PowerShell modules like Carbon, Add-HostsEntry is not part of any of those modules.
This is where Show-Command comes to rescue:
Add-HostsEntry : The term 'Add-HostsEntry' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\mvp-site\docker\tools\Scripts\Functions-HostNames.ps1:14 char:5 + Add-HostsEntry "cm.$($HostDomain)" + ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Add-HostsEntry:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Add-HostsEntry : The term 'Add-HostsEntry' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At C:\mvp-site\docker\tools\Scripts\Functions-HostNames.ps1:15 char:5
+ Add-HostsEntry "cd.$($HostDomain)"
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Add-HostsEntry:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Add-HostsEntry : The term 'Add-HostsEntry' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At C:\mvp-site\docker\tools\Scripts\Functions-HostNames.ps1:16 char:5
+ Add-HostsEntry "id.$($HostDomain)"
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Add-HostsEntry:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Comments
Post a Comment