本文介绍了使用Powershell在IIS中设置变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图自动配置网站,需要为netcore应用程序设置一些环境变量.
trying to automate the configuration of a website, it is require to setup some environment variables for an netcore application.
我准备了以下脚本:
$env:sitename="MyApp"
$env:IMAGEDIRECTORYPATH="C:\Temp\Images\"
$env:REDISINSTANCENAME="DEV"
$env:CACHESERVERHOSTIP="192.168.0.1"
$env:QUEUEMACHINENAME="BOG11"
$env:QUEUESALGORITHMSQUEUE="BOG11\private$\Algorithms"
Import-Module WebAdministration
$envVariables = (
@{name='SignalRHub';value="$env:IMAGEDIRECTORYPATH"},
@{name='ApiServerUrl';value="$env:QUEUESALGORITHMSQUEUE"}
)
$envVariables2 = (
@{name='SignalRHub3';value="$env:IMAGEDIRECTORYPATH"},
@{name='ApiServerUrl3';value="$env:QUEUESALGORITHMSQUEUE"}
)
set-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST/$env:SiteName" -filter "system.webServer/aspNetCore/environmentVariables" -name "." -value $envVariables
set-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST/$env:SiteName" -filter "system.webServer/aspNetCore/environmentVariables" -name "." -value $envVariables2
我在服务器A中运行了脚本,它运行良好.
I ran the script in Server A, it works perfectly.
然后我在服务器B中运行了脚本,我得到了:
then I ran the script in Server B, and I got this:
set-WebConfigurationProperty : The request is not supported. (Exception from HRESULT: 0x80070032)
At line:23 char:1
+ set-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST/$env:Si ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-WebConfigurationProperty], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.SetConfigurationPropertyCommand
set-WebConfigurationProperty : The request is not supported. (Exception from HRESULT: 0x80070032)
At line:24 char:1
+ set-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST/$env:Si ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-WebConfigurationProperty], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.SetConfigurationPropertyCommand
服务器B是从服务器B克隆的.
Server B was cloned from Server B.
什么可能导致此行为?
推荐答案
可以改用以下命令吗?
Set-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST" -location $env:sitename -filter "system.webServer/aspNetCore/environmentVariables" -name "." -value $envVars
这篇关于使用Powershell在IIS中设置变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!