I want to run these two commands in PowerShell in conjunction, and use the output of dir as the path in Get-ChildItem
cmd /r dir /b/s/a/t screenshot_37.png; powershell -command "& {Get-ChildItem "dir output" -recurse -force}"
Can I receive some insight into how this is possible?
(Context: I'm conducting searches of specific files, and want to know their attributes if found)
If you're calling this from PowerShell, you don't need to call
powershell.exeto runGet-ChildItem: just invoke the latter directly, which avoids the costly creation of a PowerShell child process.If you were to solve this via
cmd.exe'sdircommand (see next point for how to avoid that), you'd need:Note that I'm using
/cwithcmd.exe(/ris a rarely seen alias that exists for backward compatibility) and that I've removeddir's/toption, which has no effect due to use of/b.More fundamentally, a single
Get-ChildItemcall should suffice - no need forcmd.exe's internaldircommand: