当前位置: 动力学知识库 > 问答 > 编程问答 >

Powershell XML Replace and Save Not Updating

问题描述:

I'm trying to update a config file using powershell. But the script is not updating the config file. Greatly appreciate any assistance on how to do this properly. Thank you!

#run.config

#<?xml version="1.0" encoding="utf-8"?>

#<runmonth>201601</runmonth>

$actconfigpath = 'C:\Users\run.config'

#reportingmonth.txt

#201512

$rptmonth = Get-Content 'C:\Users\reportingmonth.txt' -First 1

[xml]$xml = Get-Content $actconfigpath

$node = $xml.runmonth

$xml.runmonth.Replace($node.ToString(),$rptmonth.toString())

$xml.Save($actconfigpath)

网友答案:

You can do this:

$rptmonth = Get-Content 'C:\Users\reportingmonth.txt' -First 1
[xml]$xml = Get-Content $actconfigpath
$xml.runmonth = [string] $rptmonth
$xml.Save($actconfigpath)
分享给朋友:
您可能感兴趣的文章:
随机阅读: