Can someone help me explain what is happening here? Sorry if this is a basic question, I simplified it from a pipeline expression I'm trying to write:
$foo = pwd
$cmd = "dir"
& $cmd $foo #Works
dir $foo #Works
& "dir $foo" #Error
*The term 'dir C:\' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.
At line:1 char:2 + & <<<< "dir $foo"*
dir pwd #Error
*Get-ChildItem : Cannot find path 'C:\pwd' because it does not exist.
At line:1 char:4 + dir <<<< pwd*
I would expect all four of these to yield the same results