任務是使用power-shell腳本更新web.config和app.config中的應用程序設置。經過一番搜索後,我發現一些腳本更新單個文件,但不是多個文件。誰能幫忙?使用PowerShell腳本更新多個配置文件
$Config = C:\inetpub\wwwroot\TestService\Web.config
$doc = (Get-Content $Config) -as [Xml]
$obj = $doc.configuration.appSettings.add | where {$_.Key -eq 'SCVMMServerName'}
$obj.value = CPVMM02
$doc.Save($Config)
所以你想Get-ChildItem和for循環? – Matt
我不確定。但這可能有幫助。你能分享怎麼做嗎? – Sridhar
$文件名= GET-ChildItem -Path 「C:\ TestService的」 -Recurse -Include的* .config 的foreach($在$文件名的文件) {\t \t $ DOC =(獲取內容$文件) - 作爲[XML ] If($ doc -match'key1'){ $ obj1 = $ doc.configuration.appSettings.add |其中{$ _。關鍵-eq '鍵1'} \t $ obj1.value = '真' $ doc.Save($文件)\t }} 這沒有工作 – Sridhar