I've got a CSV (with headers) from all of our access points and want to add them to Zabbix via XML Upload.
Since I don't want to create an XML file for each AP manually, I'll try to do this in PowerShell. But - how?
I've tried some things with (Get-Content .\Template.xml).Replace() and ForEach-Object, but I haven't had success yet.
Filenames are:
AP.csv(list of APs, headers are Hostname and IP):Hostname;IP AP1;10.29.202.101 AP2;10.29.202.102 AP3;10.29.202.103 AP4;10.29.202.104 Ap5;10.29.202.105
Template.xml:<hosts> <host> <host>Hostname</host> <name>Hostname</name> [...] <interfaces> <interface> [...] <ip>PIIP</ip> [...] </interface> <interface>The
Template.xmlhas 2 strings Called "Hostname" and 2 Called "PIIP" - Both Hostname strings should be replaced with 1 Hostname fromAP.csv, and both PIIP should be replaced with the related IP.
My Last attempt so far was:
$a = Import-Csv .\Ap.csv
$APHost = ($a).Hostname
$APIP = ($a).IP
$xml = Get-Content .\Template.xml
foreach ($row in $a) {
$xml.Replace('Hostname',$APHost).Replace('PIIP',$APIP) |
Out-File ".\Aps\$row.xml"
}
But this ended in all hostnames and all IPs where in 1 XML file.
I would like to have 1 XML file for each host at the end with hostnames and related IP.