2016-07-11 17 views
0

Ich versuche, eine Konfigurationsdatei mit Powershell zu aktualisieren. Aber das Skript aktualisiert die Konfigurationsdatei nicht. Ich schätze jede Hilfe, wie man das richtig macht. Vielen Dank!Powershell XML ersetzen und nicht aktualisieren speichern

#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) 

Antwort

0

Sie können dies tun:

$rptmonth = Get-Content 'C:\Users\reportingmonth.txt' -First 1 
[xml]$xml = Get-Content $actconfigpath 
$xml.runmonth = [string] $rptmonth 
$xml.Save($actconfigpath) 
+0

Vielen Dank! Klappt wunderbar! – mtryingtocode