If you post code, please use the ‘Insert Code’ button. Please and thank you!

codebutton2.pngAlso please have a read here regarding rather long scripts.

Why did you choose to use an alias for write host? I was confused when I was ‘DS’ but i finally saw on the top you set the alias. especially since you are new to Powershell it helps a lot if you keep stuff as original as possible, no abbreviations and shortcuts.