I'm trying to add a new element in an XML file. Below is the XML file. My goal is to add several new Svc with property Name, Displayname, Activ, CommadState, Status.
As my Svc element doesn't have an ID or other thing, I can not add then edit I've to add directly the correctly value
I've tried like this but it says that I'm trying to call a null-valued expression.
$drive = "E:"
$filePath = Get-Content $drive\Alarm\Services\ProgWatch\ProgWatchServices.xml
$doc = New-Object System.Xml.XmlDocument
$doc.Load($filePath)
$child = $doc.CreateElement("Svc")
$doc.DocumentElement.AppendChild($child)
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfSvc xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Svc>
<Name>Respus</Name>
<Displayname>Respus</Displayname>
<Activ>true</Activ>
<CommadState>NoCommand</CommadState>
<Status>Running</Status> </Svc> <Svc>
<Name>AlarmUS</Name>
<Displayname>AlarmUS</Displayname>
<Activ>true</Activ>
<CommadState>NoCommand</CommadState>
<Status>Running</Status> </Svc> <Svc>
<Name>asProgWatchGuard</Name>
<Displayname>Prog Watch Guardian</Displayname>
<Activ>true</Activ>
<CommadState>NoCommand</CommadState>
<Status>Running</Status>
</Svc>
<Svc>
<Name>asBackup</Name>
<Displayname>Data Backup</Displayname>
<Activ>true</Activ>
<CommadState>NoCommand</CommadState>
<Status>Running</Status>
</Svc>
</ArrayOfSvc>