Fix failing powershell scripts and make some operations conditional