PowerShell script to create numerous DHCP scopes

Let's say you need to create a whole bunch of DHCP scopes in the Windows DHCP server, and you don't feel like spending hours using the wizard, or manually constructing all the netsh commands you need to do it from the command line. I had this very problem last week, so I hacked together this script to take a CSV file with all the details needed for the scopes, and output a .cmd file that I can simply run against my DHCP server to create them all. I've only included the DHCP options for router address, DNS servers, and DNS suffix, but you could certainly add more.

## SCRIPT.........: Create-Scope.ps1 
## AUTHOR.........: Seth H. Bokelman 
## EMAIL..........: seth.bokelman@uni.edu 
## VERSION........: 1 
## DATE...........: 2012-04-030 
## REQUIREMENTS...: Powershell v2.0 
## DESCRIPTION....: Creates a CMD file to create numerous DHCP scopes 
## NOTES..........: Requires CSV file with these fields: SCOPE, MASK, NAME, DESC 
## CUSTOMIZE......: 
# IP address of DHCP server 
$DHCPServer = ""

#IP address of DNS servers 
$DNS1 = "" 
$DNS2 = ""

# Stores current date & time in a sortable format 
$date = Get-Date -format s

# Name of output batch file 
$outputfile = "C:DHCPscopes.cmd"

# Assumes a CSV with 8 columns listed above. 
$ips = import-csv "C:input.csv"

$ips | %{
add-content -Encoding ASCII -Path $outputfile -Value "netsh dhcp server $DHCPServer add scope $($_.SCOPE) $($_.MASK) `"$($_.NAME)`" `"$date - $($_.DESC)`""
add-content -Encoding ASCII -Path $outputfile -Value "netsh dhcp server $dhcpserver scope $($_.SCOPE) set optionvalue 3 IPADDRESS $($_.ROUTER)"
add-content -Encoding ASCII -Path $outputfile -Value "netsh dhcp server $dhcpserver scope $($_.SCOPE) set optionvalue 6 IPADDRESS $DNS1 $DNS2"
add-content -Encoding ASCII -Path $outputfile -Value "netsh dhcp server $dhcpserver scope $($_.SCOPE) set optionvalue 15 STRING `"$($_.DNSSUFFIX)`""
add-content -Encoding ASCII -Path $outputfile -Value "netsh dhcp server $dhcpserver scope $($_.SCOPE) add iprange $($_.STARTIP) $($_.ENDIP)"
add-content -Encoding ASCII -Path $outputfile -Value "netsh dhcp server $DHCPserver scope $($_.SCOPE) set state 1"
## END

Powershell script for creating DHCP reservation batch file

I've taken a handy script from Clint McGuire that creates batch files to aid in creating large groups of DHCP reservations and modified it a little bit to also insert the date in a sortable format at the start of the description field. Posting it here in case anyone else finds it useful:

## SCRIPT.........: Create-Reservation.ps1
## AUTHOR.........: originally: Clint McGuire, modified by Seth H. Bokelman
## EMAIL..........:
## VERSION........: 2
## DATE...........: 2012-04-020
## COPYRIGHT......: 2011, Clint McGuire
## LICENSE........:
## REQUIREMENTS...: Powershell v2.0
## DESCRIPTION....: Creates an CMD file to add reservations to DHCP.
## NOTES..........: Requires CSV file with 4 fields, IP, MAC, NAME and DESC
## CUSTOMIZE......:
# IP address of DHCP server
$DHCPServer = ""

# DHCP Scope you'd like reservations created for
$DHCPscope = ""

# Stores current date & time in a sortable format
$date = Get-Date -format s

# Name of output batch file 
$outputfile = "C:\DHCPreservations.cmd"

# Assumes a CSV with four columns, MAC, IP, NAME and DESC.
$ips = import-csv "C:\accesspoints.csv"

$ips | %{
add-content -Encoding ASCII -Path $outputfile -Value "netsh Dhcp Server $DHCPServer Scope $DHCPScope Add reservedip $($_.IP) $($_.MAC) `"$($_.NAME)`" `"$date - $($_.DESC)`" `"DHCP`""
## END

My new PC, part III

Since at least a couple people reading this have expressed interest in building a similar machine, I'm going to continue explaining why I chose the parts I ddi for my new machine: Intel i5-2500K CPU

I typically prefer to use AMD processors whenever possible in both my home machines and in the servers I buy at work, but with the dominance that Intel is currently displaying on the desktop, choosing anything other than a "Sandy Bridge" chip didn't seem to make a lot of sense. I've always thought that AMD chips represented a very good value, and I think that continues to be true, but I was looking to get as much performance as I could reasonably afford, and had the budget for Intel. Intel has broken their mainstream chips into the i3, i5, and i7 families. The i3 chips are aimed at budget and entry-level machines, the i5 at mainstream machines, and the i7 at performance & enthusiast computers. Intel has also made a few parts, such as the i5-2500K and the i7-2600K that are purely aimed at enthusiasts building their own machines. The K designator in the model number indicates chips with an unlocked clock multiplier, chips that are practically guaranteed to overclock, as that's the only reason to care about an unlocked multiplier… I've had a few people ask me why I didn't go with the i7-2600 instead of my i5-2500K. My reasoning was simple, the only real difference between the two is hyperthreading support on the i7. Since I don't have a lot of apps (especially games) that can use more than 4 CPU cores, I didn't really feel it was worth the price premium. Sure, the i7 is 100mhz faster than the i5, but, using the stock cooler that came with my CPU, I easily overclocked my chip to 4.3Ghz just by using the auto-overclocking feature of my motherboard.

Antec Three Hundred Case

I chose the Antec case because it had pretty good reviews from real users, was from a quality manufacturer, and had a mounting space for a 2.5" hard drive. I like that all the edges inside are rounded, so you don't slice your hand up while working in it, and I also like that there's a handy chamber for stashing any extra power supply cables you're stuck with, if you're using a non-modular power supply like I am. The two included case fans are very quiet when run at their low setting, but they don't interface with the motherboard to let it throttle them, you have to open the case and flip their switches to the speed you desire. All-in-all, it's a solid choice, and my Radeon 6870 card easily fit between the case and the 3.5" hard drive spaces, and there are room for many drives. There is not an external 3.5" slot, however, so if you're dead-set on having a floppy drive in your case, you'll want to either get an adapter or look elsewhere. Same for a card reader.

ASUS LGA 1155 Intel Z68 Chipset Motherboard P8Z68-V PRO

I really waffled on what motherboard to purchase. I had a few requirements in mind. I really wanted 4 DIMM slots so I could expand beyond the initial 8GB of memory I purchased if I ever saw a smoking deal and wanted to go to 16GB. I also wanted the full ATX formfactor, and not one of the smaller variants, because my case had room for it. Sandy Bridge has three different chipsets, and the Z68 chipset is the top-of-the-line one, that incorporates the best parts of each of the two lesser chipsets. I initially had picked out this Gigabyte board, but it went out of stock as I was going to order it, so I stepped up to the more expensive Asus motherboard, and I can't say I'm disappointed. I was able to use the one-click overclock button in the Asus software to overclock my CPU to 4.3Ghz, and installing the drivers off the included DVD was pretty painless, with a nice little menu app that let you know what you were installing. The onboard audio works well, and this motherboard, combined with the i5-2500K, actually provides pretty decent integrated video as well. If you don't really plan on playing any modern 3D games on the system, you could easily get by with the HD3000 graphics chip integrated into the CPU until you find a good deal on a graphics card you want later. The motherboard manual actually was pretty helpful too, and everything is clearly labeled and explained, unlike the cheaper boards I've used in the past, where you get a poorly Xeroxed folded page of paper or two..

Tomorrow, I'll wrap this up talking about storage, and what the total cost of building this system was.

My new PC, part II

As I wrote yesterday, I’ve built a new gaming PC for home, and I promised to write some more today about why I chose certain components.  I’ll write about two of them today, and talk a little bit about power consumption.

Antec 620W Neo Eco Power Supply

The first component I bought was the power supply.  Power supplies aren’t very exciting components, and the main reason I picked this one is that I saw it on a special on Slickdeals.  I knew that I wanted a power supply with enough power that I could eventually run two video cards in my computer (ATI/AMD calls this Crossfire) and this power supply can do that.  Also, I wanted something relatively energy efficient, and since this one has the 80 Plus certification, I won’t be wasting a lot of power by using it.  Antec is generally a quality brand, and this is a quality (and heavy)  power supply, but it isn’t a “modular” power supply, where you only attach the cables to power the specific components needed in your build.  As a result, I have a couple extra cables in my case, and it makes for a bit of a mess when you’re wiring it all up.  If I was doing this over again, I’d wait a bit longer for a deal to pop up on a modular supply, as it would make the finished product look much tidier.

HIS Radeon 6870 Video Card (H687F1G2M)

I spent a lot of time agonizing over which video card to purchase.  There are a LOT of options for video cards, at many different price points, and typically the way I choose one is by finding the fastest card at the price point I’m willing to spend.  I read numerous benchmarks, and fortunately, AnandTech is currently using Civilization 5 as one of their benchmarking games.  I’ve been playing this game quite a bit lately, so it’s a very useful benchmark, and it was pretty clear that in the $150-ish price range, the NVidia GeForce 460 cards offered the most bang for the buck in Civ 5.  However, I’ve also been mining some Bitcoins lately with my hardware, and for Bitcoin mining, the Radeon cards are the only way to go.  They’re also sort of confusing to buy, as the performance doesn’t scale cleanly with price, due to the way that the mining software uses the processing power of the card.  After pouring over a lot of breakdowns of cost, mining performance, and energy consumption, I decided on a Radeon 6870 card as being something that would perform well in Bitcoin mining, in games, and still come in at a price I could live with.  It’s actually faster than the GeForce 460 I mentioned above in most games, except for Civilization 5, but honestly, if you’re not interested in Bitcoin mining, go for the 460, you can often find good deals on them listed on Slickdeals, and you can save at least $25 over the cost of the Radeon 6870, which ran me $165 after rebate.  If you want to stick with the Radeon family, the slightly-slower Radeon 6850 is also a good choice, it’s just not nearly as good at Bitcoin mining as its bigger brother.


Power Consumption

So, how much power does this new rig of mine use?  Can I actually turn a profit on my Bitcoin mining?  I plugged in my trusty Kill-A-Watt tonight to find out, and here are the results, not counting the monitor:


State Power consumption (watts)
Off 0
Booting 100-130
Idle/Login Screen 70
Mining Bitcoins 182
Civilization V 196
Sleep 1

So, I’m clearly not stressing my 620W power supply yet, but these numbers let us easily calculate what it’s costing me to mine Bitcoins.  Our power costs us about 7.8 cents per kw-hr, so when mining Bitcoins, I’m using about 34 cents worth of power per day versus leaving my computer turned off.  At my current rate, I can earn a Bitcoin about every 4 days, and they’re currently trading at over $15 each, so I could make $13 every four days in profit.  (Obviously, that heat goes somewhere, so my air conditioning will have to work slightly harder to dissipate that heat in the summer, but I'll save natural gas in the winter, so we’ll call it a wash).


Clearly, putting the computer to sleep is a good way to cut down on your power bill, but even leaving it idle isn’t going to break the bank, at a cost of only 13 cents per day.

My new PC

As the refurbished Dell PC I bought about four years ago was getting to be a bit slow, I decided that I wanted to build myself a new PC this summer. I don't game as much on my PC as I used to, but with my current favorite, Sid Meier's Civilization V, being dog slow on my Inspiron 531, and Diablo III being just around the corner, now seemed like a good time for an update. My last three PCs were built by companies, Dell, iBuyPower, and Dell again. My Dell boxes were rock solid, my iBuyPower box had some issues pop up after a couple years, but on the whole, they worked. I'd gotten out of the habit of building my own PCs, because I'd gotten fed up with compatibility problems, flaky parts, and unstable and loud machines. Fortunately, the parts available to the PC enthusiast market have come a long ways in the last decade, and building my new PC wasn't hard at all. In fact, it passed the POST on the first try, and everything has worked well, other than the optical drive I forgot to connect to the motherboard at first. Oops.

So, here's what's inside my new PC:

  • Intel Core i5-2500K Processor 3.3GHz 6 MB Cache Socket LGA1155
  • Antec Three Hundred Gaming Case
  • ASUS LGA 1155 Intel Z68 Chipset Motherboard P8Z68-V PRO
  • HIS Radeon 6870 Video Card (H687F1G2M)
  • Seagate Momentus XT 500 GB Solid State Hybrid Drive ST95005620AS
  • PNY Optima 8 GB (2 x 4 GB) PC3-10666 1333MHz DDR3 RAM
  • Lite-On iHAP422 22x DVD±RW Drive with LightScribe
  • Antec 620W Neo Eco Power Supply
  • So that's the parts list. I'll write more tomorrow about why I chose some of those components, how it turned out, and what I'd do differently, as well as break down the cost of building a gaming rig like this.

    Resources for new Kindle owners

    As I know a lot of people have received new Amazon Kindles lately for the holidays, and have probably fallen in love with them as much as I have over the last six months of owning one, I thought I'd compile a few tips about alternative ways of getting content on them. Certainly, you can buy your eBooks all from Amazon, though there can be advantages from getting them elsewhere too, especially if it saves you money!

    One of the ways you can save a few bucks is by using the excellent free software package called Calibre to load content you already own on your Kindle. Amazon has a nice service where they will convert PDF and Word documents, among other formats, and send them to your Kindle, but they charge by the megabyte for the data they're converting for you. If you use Calibre, and just plug your USB cable into your computer, you can upload eBooks and other content for free, and cut out the middle an. Calibre is available for both Mac and PC, and it's a great app!

    Another great source for eBooks is Baen, the science fiction publisher. If Sci-Fi isn't your cup of tea, then this probably won't interest you, but the Baen Free Library has an ever-changing collection of totally free and legal eBooks for you to download for your Kindle. They started this program at the urging of some of their authors, to help generate interest in paper sales of catalog titles, as well as in the hopes that if you read one book by the author for free and love it, you'll purchase subsequent books.

    Baen also sells many other eBooks via their WebScriptions site, including many titles that simply aren't available via Amazon for the Kindle, and they're usually at a much lower price. Another nice feature of the Baen books is that they don't use any DRM on their eBooks, so you'll always be able to read them, move them to another device, or loan them out to a friend.

    Friends are another excellent source of Kindle content, as many titles can now be lent to a friend via Amazon's web page. You just need to enter a valid email address to send the eBook code to, and then that Kindle owner can have the book installed on their Kindle. It's important to note, however, that not all Kindle books on Amazon can be lent, as it's up to the publisher to enable that feature. Also, a given book you own can only be lent once, and only for a period of two weeks! Make sure the person you're lending the book to will have time to read it, and REALLY wants the book, before you use up your one lending period on them.

    This idea has also been extended to the Kindle Lending Club online, where users can swap their "lends" with each other, giving you access to far more titles than you could get from your friends.

    I'm hopeful in the future that libraries will implement a way to check out eBooks on the Kindle too. They have the ability to do it for some other platforms, and while the DRM can be removed to let the content work on a Kindle, it's something you need a computer geek to set up.

    3G Data coverage maps of Iowa

    As I’m in the market for a new cell phone and carrier, after being with Sprint (disclosure: I’m a Sprint shareholder) for 9.5 years, I did some comparison of the various 3G coverage maps of Iowa, and here they are.  You can click on the maps for larger versions of many of them:

    First up, iWireless.  Formerly known as Iowa Wireless, they’re the closest thing we have to T-Mobile here in Iowa.  Their 3G coverage is pretty weak, and is represented by the pink color on the map.  Davenport, Cedar Rapids, Cedar Falls/Waterloo, Des Moines, Ames, Council Bluffs, and Iowa City are covered, and really nowhere else..  Their service prices are good, but their phone selection tends to lag T-Mobile proper by quite a bit, and if you venture outside those cities, you’re going to be on Edge or even worse, GPRS a lot of the time…


    Next up is AT&T.  I have two maps for them, the first is their current map, the second is the coverage they plan to have on 3G by the end of March.  Cedar Falls & Waterloo went live on 3G sometime yesterday, so the map appears to be coming true.  On the first map, 3G is the dark blue.  On the second (future) map, current 3G is dark blue, future 3G is light blue, sorry it’s so tiny!



    Third is Sprint.  As I mentioned, they’re my current carrier, and cover most of the major metropolitan areas with 3G (the dark orange), though for some reason they continue to ignore Fort Dodge and Mason City, among others, as well as the I-35 corridor:


    Fourth is Verizon.  They cover most of the state with their 3G (red) coverage, though that salmon color shows they have some holes in the northwest & southwest corners.  I, personally, never go there, so it doesn’t really bother me, but I wish there was a little better coverage on US 63 north from Waterloo to Rochester, MN.


    Fifth, and best, in my opinion, is regional carrier US Cellular.  They cover almost all of the state with 3G as represented by the sickly green color, and when you’re not on their network, you’ll roam onto Verizon’s 3G network in most of the country.  For some reason, the bottom tier of Minnesota seems to be non-3G coverage in their maps, however.


    So what’s an Iowan to do?  Clearly if you’re a heavy smartphone user, and you travel outside major cities, CDMA is your only real option for technology, and the best choices are Verizon & US Cellular.  Sprint isn’t bad in Eastern Iowa, but really degrades elsewhere, and in rural areas.  The GSM carriers, iWireless and AT&T, are really only great in the major cities, over 100,000 people, but if you don’t spend any time out in little places like Ventura, Manson, or Hanlontown, Iowa, they’d be fine.  Unfortunately, I spend time in those places, and even some bigger ones, like Mason City and Fort Dodge, and I think I want 3G coverage in all of them for my next phone…

    How to install NetBackup 7.0 on Ubuntu 10.04

    NetBackup 7 officially “supports” Ubuntu Linux 8.04, 9.04, and 10.04 for Linux clients, as seen in the Software Compatibility List but the installer doesn’t “work”.

    Specifically, the problem seems to be that PBX, or Private Branch Exchange, is distributed in an RPM package along with the client.  The normal shell script that installs the client kicks an error when PBX fails to install:

    Installing PBX... ./installpbx: 1510: rpm: not found
     ERROR: Could not install VRTSpbx package
     Please see installation log for more details
     Installation log located here: 
     Installing PBX was unsuccessful.
     Aborting ...

    Opening the next log reveals more:

    [10-08-10-13:52:11] Extracting 
    /var/tmp/VRTSpbx_1928/PBX.tar.gz into 
    [10-08-10-13:52:11] Installing/Upgrading private branch 
    exchange on Linux
    [10-08-10-13:52:11] Checking for the PBX process...
    [10-08-10-13:52:11] PBX process is not running.
    [10-08-10-13:52:11] rpm -U --nodeps --nopostun --nopreun
    ./installpbx: 1568: rpm: not found
    [10-08-10-13:52:11] ERROR: Could not install VRTSpbx 
    [10-08-10-13:52:11] Removing temporary directory
    [10-08-10-13:52:11] rm -rf /var/tmp/VRTSpbx_1928
    [10-08-10-13:52:11] installpbx exiting with return 
    code: 1
    [10-08-10-13:52:11] Please see installation log for more 
    [10-08-10-13:52:11] Installation log located here:

    As this isn’t Red Hat, rpm is not present on the system, nor would it work if it was…

    With the help of the folks at Symantec, here’s what will get around this problem and help you install the client.  Hopefully they’ll put this online in a tech note soon, but I’m guessing I’m not the only person who ran into this problem, so here are my notes.  I am not a Linux wizard, by any means, but here are the required steps to make this work.  This also requires you to install alien, a package that’ll let you install rpm packages on Ubuntu:


    Get the giant 7.0 client tarball and copy it to your server.  I downloaded mine from FileConnect.

    gunzip NetBackup_7.0_CLIENTS_GA.tar.gz.gz

    tar xvf NetBackup_7.0_CLIENTS_GA.tar.gz

    cd NB_7.0_CLIENTS_GA/NBClients/anb/Clients/usr/openv/netbackup/client/Linux/RedHat2.6

    sudo mkdir /tmp/pbx

    sudo cp PBX.tar.gz /tmp/pbx

    cd /tmp/pbx

    sudo gzip -dv PBX.tar.gz

    sudo tar xvf PBX.tar

    sudo apt-get install alien

    sudo alien -i --scripts VRTSpbx-
    (you will see lots of errors, you can ignore them)

    Then start PBX on the CLIENT:
    sudo /opt/VRTSpbx/bin/vxpbx_exchanged start

    sudo nano NB_7.0_CLIENTS_GA/NBClients/anb/Clients/usr/openv/netbackup/client/Linux/RedHat2.6/cp_to_client

    Comment out lines 1723 - 1732 by inserting a # at the start of the line (use Control-W in nano to search for PBX to help locate this):

      1723 #       ${ECHO} " 
      1724 #Installing PBX..." 
      1726 #       ${SOURCE_DIR}/installpbx -f PBX.tar.gz 
      1727 #       if [ $? -ne 0 ] ; then 
      1728                 ${ECHO} " 
      1729 #Installing PBX was unsuccessful. 
      1730 #Aborting ..." 
      1731 #               exit 1 
      1732 #       fi

    Hit Control-X to save and exit.

    Then execute the "install" script in /NB_7.0_CLIENTS_GA


    You can then normally patch the client to version 7.01, as that won’t require you to use any RPM-based packages.  I've also heard that installing version 6.5.4, then upgrading from there to 7.0 will work too, as that version of PBX will install ok, but I haven’t tried it.