I tend to default to writing code in the way that most people could read the code and easily understand. Following that guideline, I would use switch. The formatted string method takes more interpretation to comprehend.
I actually wonder why you went with different functions. If they all take the same two parameters and you only switch between them depending on one external criteria you could use one big function (Get-Data) and add a third parameter to decide what logic to apply internally.
i dove head-first before doing better / deeper planning
also … i try to avoid “long” source code files (i have 1 at work that’s grown to a lil over 1k lines & i always dread cracking open that novel)
plus the way i was organizing the Repo it made logical sense to keep the Get-Data01 file “close to” it’s fellow *01 resources
for more context: i started this month strong working thru the Advent Of Code puzzles & storing my solutions in a GitHub repo
so the actual “similar” functions were Measure-Answer*
and after day 04 i wanted to be able to consistently call Measure-Answer 4 vs Measure-Answer04
some additional motivation was that if i ever really cleaned up the module i could trim down the Exported Function list to JUST the Measure-Answer command vs Measure-Answer01 … Measure-Answer25
Yeah, I actually don’t use invoke-expression myself unless there’s no other way, and I can usually find another way.
And my earlier comments were really about the overall code appearance rather than the security implications of the two options. I worked for years with a team whose understanding of PowerShell was elementary to non-existent, so clarity was always a high priority if anyone was ever going to understand it.
The good thing is that the switch example you gave can avoid invoke-expression and be easier to read. So it’s a win-win on those two points.