Search code examples
iisenvironment-variablesappcmd

How to set environment variables per site on IIS using appcmd.exe?


It is very easy to set environment variables per site on IIS Manager:

IIS

I looking for a way to do it using appcmd.exe so I can include this in my install script.

The closest I got was this:

C:\>C:\Windows\System32\inetsrv\appcmd.exe set config "dashboard" -section:system.webServer/aspNetCore /environmentVariables.[name='foo',value='bar'] /commit:apphost

-> dashboard is my site's name.

But this command returns this error:

ERROR ( message:Cannot find requested collection element. )


Solution

  • You may have figured it out already, but this format should work:

    appcmd.exe set config "dashboard" -section:system.webServer/aspNetCore /+"environmentVariables.[name='foo',value='bar']" /commit:apphost