Code: Select all
foreach($item, "<get SelectedItemsPathNames |>") {
run """C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe""
-Command ""$path = '$item';
[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');
$image = new-object System.Drawing.Bitmap $path;
$image.RotateFlip('Rotate90FlipNone');
$image.Save($path)""";
}
$selected = "C:\File 1.png","C:\File2.png";
or$selected = @("C:\File 1.png","C:\File2.png");
with quotations (") around each element.
The following does work within PowerShell itself or when triggered by the Command Prompt (either with
@($selected)
or $selected
), but as an XY script it removes any and all quotations from $selected, which makes it so that it doesn't work with multiple images. No matter how many quotations are put around it:
Code: Select all
$selected = quote(<get SelectedItemsPathNames '", "'>);
run """C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe""
-Command ""Foreach ($path in @($selected)) {
[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');
$image = new-object System.Drawing.Bitmap $path;
$image.RotateFlip('Rotate90FlipNone');
$image.Save($path);
}"""
$selected = @(C:\File 1.png,C:\File2.png);
which makes PowerShell think it are functions (so if it does anything at all, like in case a path doesn't contain any spaces, it will open the image without doing anything else).For PowerShell troubleshooting, one can put
-NoExit
in front of -Command
.I have also tried moving the array around, or not defining it at all putting it directly in the Foreach, but with the same result. What would be the proper way to go about it to retain the quotations around the array elements?