Refactor powershell scripts