Hello,
As you want to know about coding an PowerShell script, I would recommend that you post the issue on the TechNet Scripting Forum where you will get better support for any issues related to scripting.
http://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
Thank you.