I have been attempting this same thing, and while writing a response to say that i couldnt get it to work, i got it to work..
I had been trying to call the script from the command line, rather than the powershell prompt. When i do it from the powershell prompt it works.
edit: i take that back.. calling the script directly from Powershell doesnt work. I'm not 100% certain what to call the prompt that i got it working from. I have the line from your above link in my code at the beginning (the bit on that page that is realted to manual registration). When i run my script from powershell or command prompt, that line in the code makes it open another prompt window, which i guess is the IIS powershell, and that is where i have gotten my script to work from.