Powershell 通过脚本设置IIS环境变量
我想通过appcmd/batch文件或PowerShell脚本自动添加/删除/编辑IIS、asp.net核心网站环境变量,不仅是一个网站的变量,而且是批量操作。虽然我可以通过使用iisui来实现这一点 虽然我可以使用appcmd添加环境变量 appcmd.exe重置配置“变量” -节:system.webServer/aspNetCore/+“环境变量。[name='foo',value='bar']”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']” 我无法通过单击单个按钮来添加/删除/更新多个网站的环境值,而不是通过每个网站的配置设置来设
我无法通过单击单个按钮来添加/删除/更新多个网站的环境值,而不是通过每个网站的配置设置来设置多个值,之后我可以在Azure DevOps管道中使用该内联脚本,您可以将多个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'}
这就是grea,t我如何删除/编辑已经添加的环境值?非常好,现在只有最后一件事,如何编辑值?我同时添加了edit和remove语句。你错过了吗?太好了,太棒了,现在所有的凝乳手术都能用了谢谢
PS C:\WINDOWS\system32> & "D:\floder1\xxx.ps1"