I need to run this command, which is read from another script.
$command = "$arr = @($input)
$arr.count
Write-Host $arr[0]"
"Classical Music for When You are on a Deadline." | & cmd /C powershell -Command {$command}
So I am getting something through the pipe and then I use it in my string command. The code does not work because $command
is not expanded to the string inside the call and therefore unknown in the launched powershell command.
These work as expected, but the commands are not taken from a string:
"Classical Music for When You are on a Deadline." | & cmd /C powershell -Command {Invoke-Expression "Write-Host $input"}
# No: System.Management.Automation.Runspaces.PipelineReader`1+<GetReadEnumerator>d__20[System.Object]
# "Classical Music for When You are on a Deadline." | & cmd /C powershell -Command {Write-Host $input}
"Classical Music for When You are on a Deadline." | & cmd /C powershell -Command {$arr = @($input)
$arr.count
Write-Host $arr[0]}