A couple of things:
1) It seems like in your function you create an object to reference your instance, but I could not tell that the server object was actually being used anywhere in your method call to create a db role.
2) Alternatively if you have to user PowerShell for this would it not be much easier to just use invoke-sqlcmd?
Joie Andrew
"Since 1982"