Skip to content

Instantly share code, notes, and snippets.

@Paxxi
Created October 18, 2014 10:31
Show Gist options
  • Save Paxxi/68b64ef19d0e68c255d0 to your computer and use it in GitHub Desktop.
Save Paxxi/68b64ef19d0e68c255d0 to your computer and use it in GitHub Desktop.
Working with pfsense dhcpd.xml in Powershell
#Load our template xml to have something to work with
[xml]$out =[xml]@"
<?xml version="1.0"?>
<dhcpd>
<lan>
<enable/>
<range>
<from>192.168.1.100</from>
<to>192.168.1.199</to>
</range>
</lan>
</dhcpd>
"@
#Set our dhcpd start range just to show how easy it is
#to work with xml in PS :)
$out.dhcpd.lan.range.from = "192.168.0.0"
#Dummy loop to show the concept
1..10 | foreach {
#Create a new element for staticmap and save it in $node until we're ready
#to use it
$node = $out.CreateElement("staticmap")
#Add the child nodes we're interesed in, have omitted descr
$node.AppendChild($out.CreateElement("mac"))
$node.AppendChild($out.CreateElement("ipaddr"))
#Set the values we want on our newly created child nodes
$node.ipaddr = "192.168.0." + $_
$node.mac = "xx:xx:xx:" + $_
#We're done, append our new staticmap to the config and repeat
$out.dhcpd.AppendChild($node)
}
#Save the whole thing as a valid xml document
$out.Save("c:\tmp\dhcpd.xml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment