This is possible. I have a script that does something similiar but I am using integrated security. Check out this link as I think it will help you out.
You can check out some of mine here.
Feel free to use my code or take out parts you need and do what you need with it. Hope it helps.