Replace $script: variables with proper parameter passing. - Use $PSBoundParameters and splatting instead of global state.
Replace $script: variables with proper parameter passing.