How can I automate the following steps by using PowerShell? :
To set the environmental variable using PowerShell you need to use the assignment operator (=). If the variable already exists then you can use the += operator to append the value, otherwise, a new environment variable will be created.
Go to your application in IIS and choose Configuration Editor . Choose Applicationhost. config ... in From combobox. Right click on enviromentVariables element, select 'environmentVariables' element , then Edit Items .
Think of Env: as a drive, it's just like the C:, except Env: contains not folders but variables such as 'Path' or 'Windir'. We are going to use PowerShell to manipulate the System variables, this is an alternative to using the Windows GUI and navigating to the Control Panel, System and 'Advanced system settings'.
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'}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With