I have run into a problem while writing my first basic PowerShell utility. I need to open an Explorer window with a file selected, but can't get the syntax of the command right.
I found this answer on SO, https://stackoverflow.com/a/12162855/957246 and had a read of this excellent blog on external commands, http://edgylogic.com/blog/powershell-and-external-commands-done-right/ - but still can't get it to work.
This is my example script (test.ps1):
$myFile = "C:\Projects\Scripts\any.txt"
# The backslash-backticks are to escape the speech marks, once for PowerShell and then again for DOS
& "C:\Projects\Scripts\EchoArgs.exe" /select",\`"$myFile\`""
& "explorer" /select",\`"$myFile\`""
..and this is the batch file that calls it, in case there's something wrong with the way I'm calling the PowerShell script:
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\Projects\Scripts\test.ps1'"
I've tried a few different combinations and the output from echoargs suggests that the syntax is right (assuming the parameter string for explorer is taken as a single string) but whatever I try just opens an explorer window on 'my documents' and the parameters are ignored/being thrown away somewhere.
There's a bit on the MSDN page for explorer.exe switches that says the comma is an empty parameter, maybe that's the thing I need to be providing by formatting the command differently?