scorpion5211
scorpion5211

Reputation: 1070

PowerShell sript to set IIS environment variable

How can I automate the following steps by using PowerShell? :

  1. Go to IIS and choose a website (website name will most likely be passed down in script as a parameter)
  2. Go Inside the Configuration Editor enter image description here
  3. Choose the aspNetCore Section in the dropdown enter image description here
  4. Go inside the environmnetVariables enter image description here
  5. Add new Collection enter image description here
  6. Create new environment varialbe enter image description here

Upvotes: 5

Views: 2782

Answers (1)

scorpion5211
scorpion5211

Reputation: 1070

Thanks to Lex Li, Seems like Configuration Editor generates scripts automatically before savings. This has lead me to getting the final PS script to be:

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/WEBSITENAME'  -filter "system.webServer/aspNetCore/environmentVariables" -name "." -value @{name='EnvironmentVariableName';value='EnvironmentVariableValue'}

Upvotes: 12

Related Questions