Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 通过脚本设置IIS环境变量_Powershell_Asp.net Core_Iis_Environment Variables_Appcmd - Fatal编程技术网

Powershell 通过脚本设置IIS环境变量

Powershell 通过脚本设置IIS环境变量,powershell,asp.net-core,iis,environment-variables,appcmd,Powershell,Asp.net Core,Iis,Environment Variables,Appcmd,我想通过appcmd/batch文件或PowerShell脚本自动添加/删除/编辑IIS、asp.net核心网站环境变量,不仅是一个网站的变量,而且是批量操作。虽然我可以通过使用iisui来实现这一点 虽然我可以使用appcmd添加环境变量 appcmd.exe重置配置“变量” -节:system.webServer/aspNetCore/+“环境变量。[name='foo',value='bar']” 我无法通过单击单个按钮来添加/删除/更新多个网站的环境值,而不是通过每个网站的配置设置来设

我想通过appcmd/batch文件或PowerShell脚本自动添加/删除/编辑IIS、asp.net核心网站环境变量,不仅是一个网站的变量,而且是批量操作。虽然我可以通过使用iisui来实现这一点

虽然我可以使用appcmd添加环境变量

appcmd.exe重置配置“变量” -节:system.webServer/aspNetCore/+“环境变量。[name='foo',value='bar']”


我无法通过单击单个按钮来添加/删除/更新多个网站的环境值,而不是通过每个网站的配置设置来设置多个值,之后我可以在Azure DevOps管道中使用该内联脚本,您可以将多个powershell写入一个文件并执行它。这里有一个例子供参考

  • 创建一个名为“xxx.ps1”的文件

  • 编写多个powershell语句

    Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Core Web Site'  -filter "system.webServer/aspNetCore/environmentVariables" -name "." -value @{name='foo';value='bar'}
    
    
    Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Core Web Site'  -filter "system.webServer/aspNetCore/environmentVariables" -name "." -value @{name='doc';value='qwe'}
    
    
    Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/aspNetCore/environmentVariables" -name "." -value @{name='foo';value='bar'}
    
    
    Write-Output ('Execute succeed')
    
    编辑并删除环境值

    Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Core Web Site'  -filter "system.webServer/aspNetCore/environmentVariables/environmentVariable[@name='foo' and @value='bar']" -name "name" -value "foo2"
    
    
    Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Core Web Site'  -filter "system.webServer/aspNetCore/environmentVariables/environmentVariable[@name='foo' and @value='bar']" -name "value" -value "bar2"
    
    
    Remove-WebConfigurationProperty  -pspath 'MACHINE/WEBROOT/APPHOST/Core Web Site'  -filter "system.webServer/aspNetCore/environmentVariables" -name "." -AtElement @{name='foo1';value='bar1'}
    
  • 打开powershell以执行文件(文件的路径+名称)


  • 这就是grea,t我如何删除/编辑已经添加的环境值?非常好,现在只有最后一件事,如何编辑值?我同时添加了edit和remove语句。你错过了吗?太好了,太棒了,现在所有的凝乳手术都能用了谢谢
    PS C:\WINDOWS\system32> & "D:\floder1\xxx.ps1"