小编san*_*san的帖子

如何使用powershell更改web.config文件的值

您好我正在尝试更改web.config文件的连接字符串的值,但收到错误:

该物业'connectionString'不能在此对象上找到.验证该属性是否存在且可以设置.

这是我正在使用的脚本:

$webConfig = 'C:\Users\test\Desktop\web\web.config'
$doc = (Get-Content $webConfig) -as [Xml]
$obj = $doc.configuration.appSettings.add | where {$_.Key -eq 'CommandTimeOut'}
$obj.value = '60'
$config = [xml](gc $webConfig)  
$con= $config.configuration.connectionStrings.add|where-object{$_.name -eq "password"};

$con.connectionString = $con.connectionString -replace "123456", "admin1234"

$doc.Save($webConfig)
Run Code Online (Sandbox Code Playgroud)

我已经修改了下面的代码,但它仍然没有工作,我得到了同样的错误.

$cfg = [xml](gc $webConfig) 
$con= $cfg.configuration.connectionStrings.add|where-object{$_.name -eq "password"};
$cfg.configuration.connectionStrings.add.connectionString=   
$cfg.configuration.connectionStrings.add.connectionString -replace "123456","admin123"
$doc.Save($webConfig)
Run Code Online (Sandbox Code Playgroud)

powershell

8
推荐指数
2
解决办法
2万
查看次数

如何在PowerShell中移动文件夹及其内容

我试图将一个文件夹及其内容从1个位置移动到另一个位置.该文件夹的名称是c:\ logfiles,它有子文件夹和文本文件,但我写的脚本,它只移动日志文件的内容,但我想将整个logfiles文件夹移动到一个新的位置

$current_logfiles = 'C:/LogFiles/*'
$new_logfiles = 'C:\My_Project\LogFiles\'

if (!(Test-Path -path $new_logfiles  )) {
New-Item $new_logfiles -type directory

Move-Item  -Path  $current_logfiles  -Destination $ $new_logfiles -Recurse -force
Run Code Online (Sandbox Code Playgroud)

}

powershell

1
推荐指数
1
解决办法
5825
查看次数

标签 统计

powershell ×2