update while function to not use invoke-expression but execute scriptblocks