Is there a better approach for passing information into script blocks in where-object filter scripts than using parent-scoped variables?
Background:
I have a script that looks for un-checked-in and/or modified source files vs. source control and has a parameter that allows it to do a more exhaustive search. I use where-object in a couple of places with a script block object contained in a script-scoped variable that I customize based on the input parameters to the script.
So, if you ask for a thorough search, the filter will compare the candidate file against all TFS files to see if the file isn't in source control, if you choose the less-thorough search, the filter will only compare against checked-out files to see if the file is modified but not checked out.
The customized script blocks refer to script-scoped variables containing the results of doing queries against source control.
So my problem is that I'd like to get rid of a global (script-level) variable and pass all the necessary information into the script blocks as parameters to the script blocks. If I was using invoke-command, I'd use the ArgumentList parameter to do this. Where-Object doesn't seem to have that. One downside of using parent-scoped variable references in the script blocks is that I can't change those variables, so I can't do lazy initialization (or at least I haven't figured out how yet, not being an expert on the scoping rules for Powershell.)