How to Fix Sitecore “Set-EnvFileVariable” Docker Error

This is how we fixed the following Sitecore Docker error: “’Set-EnvFileVariable is not recognized as the name of a cmdlet, function, script file, or operable program.”

March 12, 2025

By Tyler Holmes

How We Got the “Set-EnvFileVariable” Error

Usually the only time you get major docker problems is when you try to set up a new developer environment for a new project; you could be doing exactly that, setting up a new project and getting this Set-EnvFileVariable error. Or you could be like me and randomly have this error appear after having zero issues the day before!

After doing a ./up.ps1 to get the latest images from Sitecore XM Cloud, I was hit with the following error:

Set-EnvFileVariable : The term 'Set-EnvFileVariable' 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:\Users\User\Documents\GitHub\PROJECT_NAME\up.ps1:33 char:5
+     Set-EnvFileVariable "NODEJS_VERSION" -Value $xmCloudBuild.renderi ...
+     ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-EnvFileVariable:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException

Note the error "Set-EnvFileVariable" is not recognized in the console.

How We Fixed the "Set-EnvFileVariable Is Not Recognized Error"

Set-EnvFileVariable is a custom function Sitecore has developed, that is a part of SitecoreDockerTools. The most likely source of your issue is not having SitecoreDockerTools installed. Even if you’ve installed SitecoreDockerTools in the past and everything was working yesterday, you should still verify its installation.

To verify the installation, run the following command directly in PowerShell: Get-Command -Module SitecoreDockerTools.

If SitecoreDockerTools is installed, you should see a response similar to the following from PowerShell:

Image of PowerShell Output Verifying SitecoreDockerTools Installation

If SitecoreDockerTools is no longer installed, you won't get a response at all. Congratulations - this is your problem. Copy/Paste the following command into your PowerShell to install SitecoreDockerTools, and it should fix your Set-EnvFileVariable error.

Register-PSRepository -Name SitecoreGallery -SourceLocation https://nuget.sitecore.com/resources/v2/
Install-Module SitecoreDockerTools

This entire command should be copied and pasted as one line in your PowerShell window.

Note, issues installing with Chocolatey:

When I initially had this problem, I immediately tried to reinstall the SitecoreDockerTools using Choco. For those of you who don't know, Chocolatey is a very common package installer; However, running the following Choco command to install SitecoreDockerTools didn't fix my issue. If you have an error installing using the original method I provided above, feel free to use the following command via Chocolatey, but take note that this command didn't work for me. I assume that Choco didn't install SitecoreDockerTools globally.

Chocolatey:

choco install SitecoreDockerTools --version 10.3.40 --source https://sitecore.myget.org/F/sc-powershell/api/v2

Potential Causes

If you're like me, you need to also know WHY something like this just randomly broke. Even after all my digging, I'm not entirely sure what caused my SitecoreDockerTools to be uninstalled. As I mentioned above, everything was working fine the previous day.

Checking my Windows logs, I saw that windows installed some updates - this is the only potential cause I could find.

Other Things We Tried Along the Way

It's highly likely that the above solution of reinstalling SitecoreDockerTools fixed your issue, but in case it didn't (or if you have new errors after fixing Set-EnvFileVariable) you can try some of the following solutions:

Reinstall PowerShell

The first thing I did was reinstall PowerShell. While you're doing this, you should double-check that the version of PowerShell you're using has been reported to have issues with Sitecore. At Fishtank we get all devs to use PowerShell 5.1.

You can check your PowerShell version using this command: $PSVersionTable.PSVersion.

Image of PowerShell Output Checking Version with $PSVersionTablePSVersion

To reinstall PowerShell you want to open the windows run tool (Win + R) and type optionalfeatures.exe.

Image of PowerShell Reinstall Accessing Windows Features via optionalfeaturesexe

Look for Windows PowerShell, uncheck it and reboot your PC. Then open the “optional features” menu back up and re-enable PowerShell.

Image of Windows PowerShell Folders Checked Before Rebooting PC

Remove “$” from Variables in Your “.env”

This blog from Jeremy Davis does a great job at highlighting some common up.ps1 issues you might have. Go read his blog for more details, but the high level overview is to remove special characters (mainly $) from your .env variables.

Here are some of the .env values you should check:

  • TELERIK_ENCRYPTION_KEY
  • MEDIA_REQUEST_PROTECTION_SHARED_SECRET
  • SITECORE_FedAuth_dot_Auth0_dot_ClientSecret

If you find any $ values, you should replace it with an alphanumeric value.

Change Your Node Version

The final thing we tried (before realizing Chocolatey didn't reinstall SitecoreDockerTools correctly) was ensuring my node version matched the project.

Changing node versions is something that can be painful, but if you use Node Version Manager (NVM) you can select the exact node version you want to use and install/switch between them seamlessly.

Just install NVM and run nvm help in PowerShell. This will list all the commands you can use. The ones you will most likely want are nvm install {nodeVersionNumber} and nvm use {nodeVersionNumber}.

Tyler Holmes

Full Stack Developer | Sitecore Technology MVP

Tyler is an experienced Full Stack Developer who has worked on a plethora of unique projects. He possesses a deep understanding of Technical SEO, C#, and React/Next.js. Tyler is also a Sitecore Tech MVP!