Whoever wrote this script seems to be missing some PowerShell basics.
For example -- if (($args.Count) -eq 2) -- there's no need for that. Declare and use proper parameters, and you can even use comment-based help to document them.
I would ask whoever wrote the script to assist you. Unfortunately this isn't the right place to paste a "code dump" and ask others to figure out what you mean and update the script to match your mental specifications.
-- Bill Stewart [Bill_Stewart]