Hi Steve,
Glad you liked the .NET Rocks show. It was certainly fun to do. Carl and Richard are great guys and they put on a great show.
Invoke-Expression will still work for you. You just need to make sure that you don't evaluate your input variable, but that you do evaluate the name of the script. Like this:
switch ($file.GetType()) {
"System.Object[]" { Invoke-Expression "`$file | '$script'" }
"System.String" { Invoke-Expression "Get-ChildItem `$file | '$script'" }
}
The backtick tells PowerShell to leave the variable be when it evaluates the string expression, so if you have a string or a collection, it remains a string or a collection. Without it the first Invoke-Expression wouldn't work properly.
I missed the first case in your switch statement when I first looked over your script. Sorry for the confusion.
I need to finish my blog entry about how to make a ps1 file that works both as a dot-sourced function and as an invoked script...
--
Kirk Munro [MVP]
Poshoholic
http://www.poshoholic.com