问题描述:

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)
相关阅读:
Top